reset()

reset() — Set the internal pointer of an array to its first element.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

reset() rewinds array's internal pointer to the first element and returns the value of the first array element.

Signature

reset(array|object &$array): mixed

Parameters

ParameterTypeWhat it takes
&$arrayarray|objectThe input array.

Return value

Returns the value of the first array element, or false if the array is empty. This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

Example

A runnable snippet:

$array = array('step one', 'step two', 'step three', 'step four'); // by default, the pointer is on the first element echo current($array) . "<br />\n"; // "step one" // skip two steps next($array); next($array); echo current($array) . "<br />\n"; // "step three" // reset pointer, start again on step one reset($array); echo current($array) . "<br />\n"; // "step one"

Changelog

VersionChange
8.1.0Calling this function on objects is deprecated. Either convert the object to an array using get_mangled_object_vars() first, or use the methods provided by a class that implements Iterator, such as ArrayIterator, instead.
7.4.0Instances of SPL classes are now treated like empty objects that have no properties instead of calling the Iterator method with the same name as this function.

See also

current(), end(), next(), prev(), array_key_first()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page reset() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.