Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

current

Returns the element the array's internal pointer points to.

Syntax

current(array|object $array): mixed

Parameters

ParameterTypeDescription
$arrayarray|objectThe 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 first

Notes

Modern code rarely uses the pointer: take the first element via array_key_first() and iterate with foreach.

See also

  • reset — Returns the first element of an array.
  • end — Returns the last element of an array.
  • key — Returns the key of the array's current element.

In the tutorial

  • Arrays — Lists and associative arrays in PHP — creating, changing, iterating and useful functions.

Thanks for reading!

Donate to the site — we work hard for you.