Computer >> Computer tutorials >  >> Programming >> PHP

reset() function in PHP


The reset() function sets the internal pointer of an array to its first element. It returns the value of the first array element. It returns FALSE if the array is empty

Syntax

reset(arr)

Parameters

  • arr − The array to be used

Return

The reset() function returns the value of the first array element. It returns FALSE if the array is empty.

Example

The following is an example −

<?php
   $arr = array("one", "two","three", "four", );
   echo current($arr);
   echo next($arr);
   echo next($arr);
   echo reset($arr);
   echo next($arr);
?>

Output

one
two
three
one
two