current
Returns the element the array's internal pointer points to.
Syntax
current(array|object $array): mixedParameters
| Parameter | Type | Description |
|---|---|---|
| $array | array|object | The array. |
Return value
mixedThe current element, or `false` if the pointer is past the end.
Examples
Moving the pointer:
<?php
$queue = ['first', 'second', 'third'];
echo current($queue), ' ';
next($queue);
echo current($queue), ' ';
reset($queue);
echo current($queue);Output:
first second firstNotes
Modern code rarely uses the pointer: take the first element via array_key_first() and iterate with foreach.
See also
In the tutorial
- Arrays — Lists and associative arrays in PHP — creating, changing, iterating and useful functions.