How to Reset an Array in PHP
After you loop through a PHP array, the current referenced array index is the last element. To move back to the first element and reset the array, you use the "reset" function. The reset function moves the PHP pointer back to the first element, so you can loop through the array again or display the first element to the user.
Instructions
-
-
1
Right-click the PHP file you want to edit, then click "Open With," then choose your PHP editor in the sub-menu.
-
2
Find the array you want to reset in your code. If you do not already have an array defined, use the following code to create an array:
$colors = array("1" => "blue", "2" => "purple");
-
-
3
Reset the array. The following code resets the array pointer to the first value, which is "blue" in the example:
reset($colors);
-
1