YouTip LogoYouTip

Func Array Reset

# PHP reset() Function [![Image 3: PHP Array Reference](#)Complete PHP Array Reference](#) ## Example Output the value of the current element and the next element in the array, then reset the internal pointer of the array to the first element: <?php $people = array("Peter", "Joe", "Glenn", "Cleveland"); echo current($people) . "
"; echo next($people) . "
"; echo reset($people); ?> [Run Example Β»](#) * * * ## Definition and Usage The reset() function moves the internal pointer to the first element in the array and outputs it. Related methods: - Returns the value of the current element in the array. - Moves the internal pointer to the last element in the array and outputs it. - Moves the internal pointer to the next element in the array and outputs it. - Moves the internal pointer to the previous element in the array and outputs it. - Returns the key and value of the current element and moves the internal pointer forward. * * * ## Syntax reset(_array_) | Parameter | Description | | :--- | :--- | | _array_ | Required. Specifies the array to use. | ## Technical Details | Return Value: | Returns the value of the first element on success, or FALSE if the array is empty. | | :--- | | PHP Version: | 4+ | * * * ## More Examples ## Example 1 Demonstration of all related methods: <?php $people = array("Peter", "Joe", "Glenn", "Cleveland"); echo current($people) . "
"; // The current element is Peter echo next($people) . "
"; // The next element of Peter is Joe echo current($people) . "
"; // Now the current element is Joe echo prev($people) . "
"; // The previous element of Joe is Peter echo end($people) . "
"; // The last element is Cleveland echo prev($people) . "
"; // The previous element of Cleveland is Glenn echo current($people) . "
"; // Now the current element is Glenn echo reset($people) . "
"; // Moves the internal pointer to the first element of the array, which is Peter echo next($people) . "
"; // The next element of Peter is Joe print_r (each($people)); // Returns the key and value of the current element (now Joe), and moves the internal pointer forward ?> [Run Example Β»](#) * * Complete PHP Array Reference](#)
← Func Cal JdtounixFunc Array Range β†’