Home >>PHP Array Functions >PHP reset() Function

PHP reset() Function

PHP reset() Function

PHP reset() function is used to move the internal pointer of array to the first element of that array. It accepts only a single parameter $array that is the given input array.  It returns the first element of the array on success and FALSE if the array is empty.

Syntax:

reset($array); 

Parameter Values

Parameter Description
array This is a required parameter. It defines the array to use.

Here is an example of reset() function in PHP:

<html>
<body>
<?php
$x = array("A","B","C","D","E","F","G");
echo current($x)."<br>";
echo next($x)."<br>";
echo reset($x);
?>
</body>
</html>
Output:
A
B
A

Example 2:

<html>
<body>
<?php
$x = array("A","B","C","D","E","F","G");
echo current($x)."<br>";
echo next($x)."<br>";
echo current($x)."<br>";
echo prev($x)."<br>";
echo end($x)."<br>";
echo prev($x)."<br>";
echo current($x)."<br>";
echo reset($x)."<br>";
echo current($x);
?>
</body>
</html>
Output:
A
B
B
A
G
F
F
A
A

No Sidebar ads