PHP - Function reset()


Advertisements


Syntax

reset ( $array );

Definition and Usage

The reset() function rewinds array's internal pointer to the first element and returns the value of the first array element, or FALSE if the array is empty.

Parameters

ParameterDescription
arrayRequired. Specifies an array

Return Value

Returns the first element in an array.

Example

Try out following example:

<?php
$transport = array('foot', 'bike', 'car', 'plane');
$mode = current($transport); 
print "$mode <br />";
$mode = next($transport);  
print "$mode <br />";
$mode = current($transport)
print "$mode <br />";; 
$mode = prev($transport);  
print "$mode <br />";
$mode = end($transport);   
print "$mode <br />";
$mode = reset($transport);   
print "$mode <br />";
$mode = current($transport); 
print "$mode <br />";
?> 

This will produce following result:

foot
bike
bike
foot
plane
foot
foot 

php_function_reference.htm