PHP reset() function

PHP range() function
PHP rsort() function

In this article, you will learn how to reset the internal pointer of an array. By resetting it means to move the pointer to point to the first element of the array which is the default behavior of the pointer. The reset() function perform this functionality.

What is the syntax of the reset() function in PHP?

reset(array)
ParameterDetails
arrayThe array to reset the internal pointer of – Required
PHP reset() function

Examples of reset() function

Example 1. Get the current, next value of the array, and then check the pointer after resetting it.

<?php
$arr= array("Jawad", "Ahmad", "Sumerina");
echo current($arr);
echo next($arr);
echo reset($arr);
?>

Example 2. In this example, you will find all the methods related to the reset method category. These methods work with the internal pointer of the arrays.

<?php
$members= array("Jawad", "Ahmad", "Sumerina", "ACS");

// Current element: Jawad
echo current($people) . "<br>";

// Next element of Jawad: Ahmad
echo next($people) . "<br>"; 

// Now the current element: Ahmad
echo current($people) . "<br>"; 

// Previous element of Ahmad: Jawad
echo prev($people) . "<br>"; 

// Last element: ACS
echo end($people) . "<br>"; 

// Previous element of ACS: Sumerina
echo prev($people) . "<br>"; 

// Current element: Sumerina
echo current($people) . "<br>"; 

// Move the internal pointer to the first element of the array:Jawad
echo reset($people) . "<br>"; 

// Next element of Jawad: Ahmad
echo next($people) . "<br>"; 

// Get key and value of Ahmad (current element) then moves the internal pointer forward
print_r (each($members));
?>
PHP range() function
PHP rsort() function
en English
X
Scroll to Top