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 −

Live Demo

<?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

Updated on: 30-Jul-2019

160 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements