reset() function in PHP || PHP Reset Function

reset() function in php

Last Updated by Pooja Chikara 25-Apr-20

0 358


PHP reset() function is used to reset the position of array pointer means it set the current pointer of an array to the starting item of the array.

Syntax:

reset($array);

here,

$array is a PHP array.


Example:

<?php
$arr1 = array("apple","orange","banana","fig",);
$last_value=end($arr1); // it will set the array pointer to last item and return the last item of array i.e. fig
$reset_value=reset($arr1); // it will reset the array pointer and return the initial element of array i.e. apple
echo "Reset item of array is $reset_value ";
?>

Output:

reset() function in php

Note: You should also read prev(), next(), current() and end() functions.


Share:


Leave a Reply


Comments
    Waiting for your comments