PHP reset

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP: reset() function

reset() function

The reset() function used to move the array's internal pointer to the first element.

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

Version

(PHP 4 and above)

Syntax

reset(array_name)

Parameter

Name

Description

Required /
Optional

Type

array_name

The input array.

Required

Array

Return value

The value of the first array element or FALSE if the array is empty.

Value Type : *Mixed.
*Mixed : Mixed indicates that a parameter may accept multiple (but not necessarily all) types.

Pictorial Presentation :

php array reset() function

Example :

  1. $val1 = array('Language', 'Math', 'Science', 'Geography');  

  2. echo current($val1);  

  3. echo'
    ';  

  4. next($val1);  

  5. echo current($val1);  

  6. echo'
    ';  

  7. reset($val1);  

  8. echo current($val1);  

  9. ?>  

Output :

Language

Math

Language