The reset() function is an inbuilt function in PHP.
- This function is used to move any array’s internal pointer to the first element of that array.
- While working with arrays, it may happen that we modify the internal pointer of an array using different functions like prev() function, current() function, key() function etc.
- The reset() function resets the internal pointer to point to the first element of the array.
Syntax:
reset($array)
Parameters: This function accepts a single parameter $array. It is the array for which we want to reset the internal pointer to point to the first element again.
Return Value: It returns the first element of the array on success, or FALSE if the array is empty i.e, the array does not contain any element.
Below programs illustrate the reset() function in PHP:
Program 1:
<?php
$arr = array ( 'Ram' , 'Rahim' , 'Geeta' , 'Shita' );
$res = reset( $arr );
print "$res" ;
?>
|
Output:
Ram
Program 2:
<?php
$arr = array ( 'Delhi' , 'Kolkata' , 'London' );
print current( $arr ). "\n" ;
next( $arr );
print current( $arr ). "\n" ;
reset( $arr );
print current( $arr );
?>
|
Output:
Delhi
Kolkata
Delhi
Reference:
http://php.net/manual/en/function.reset.php
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
20 Jun, 2023
Like Article
Save Article