In PHP, current() returns the value of the array element that the internal pointer is pointing at.
Every array has a hidden pointer that starts at the first item. current() reads the item there without moving the pointer. Functions like next(), prev(), reset() and end() move it.
Syntax
Call current() with the values you need. Start with this line.
PHP
$value = current($letters);
Call
What it does
current($letters)
Returns the item at the pointer, the first one by default.
next($letters); current($letters)
Moves the pointer forward, then reads the new item.
current([])
Returns false for an empty array.
current() is an alias of pos(). Most modern code uses foreach instead of moving the internal pointer by hand, but current() is still useful when you just want the first item (combined with reset()).
Library declarations
PHP
current(array|object $array): mixed
Parameters
Parameter
Description
array
Required. The array to read from. Passing an object is deprecated since PHP 8.1.
Return Value
Return Value
Description
mixed
The value at the current pointer position.
false
Returned if the array is empty or the pointer has moved past the last item.
PHP Examples
Example 1 — Read the Current Item
Read the first item, move the pointer, and read again.