PHP current() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

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);
CallWhat 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

ParameterDescription
arrayRequired. The array to read from. Passing an object is deprecated since PHP 8.1.

Return Value

Return ValueDescription
mixedThe value at the current pointer position.
falseReturned 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.

PHP
<?php
$letters = ["x", "y", "z"];

echo current($letters), PHP_EOL;
next($letters);
echo current($letters), PHP_EOL;

How It Works

  1. A new array has its pointer on the first item.
  2. current() returns "x" and does not move the pointer.
  3. next() moves the pointer to the second item.
  4. The next call to current() returns "y".

Example 2 — Empty Array and Past the End

current() returns false when there is nothing to read.

PHP
<?php
$empty = [];
var_dump(current($empty));

$one = ["a"];
next($one);
var_dump(current($one));

How It Works

  1. An empty array has no current item, so current() returns false.
  2. The second array has only one item, "a".
  3. next() moves the pointer past that item to the end.
  4. current() now returns false again.

Example 3 — Jump to the First and Last Item

Combine current() with reset(), end() and key().

PHP
<?php
$data = ["a" => 1, "b" => 2, "c" => 3];

end($data);
echo key($data), ": ", current($data), PHP_EOL;

reset($data);
echo key($data), ": ", current($data), PHP_EOL;

How It Works

  1. end() moves the pointer to the last item.
  2. key() gives the key "c" and current() gives the value 3.
  3. reset() moves the pointer back to the first item.
  4. Now key() and current() report "a" and 1.

Frequently Asked Questions

It returns the value of the array item at the internal pointer without moving the pointer.
Use next(), prev(), reset() and end(). Each one moves the pointer and returns the new current value.
Either the array is empty, the pointer is past the last item, or the current item itself is false. Use key() to check if the pointer is valid.
They are the same. pos() is an alias of current().
Usually no. foreach is clearer and safer. current() is best for quick reads such as getting the first or last item.

Next: each()

each() was a function that returned the current key and value of an array as a pair and th.

each() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful