Latest web development tutorials

PHP reset () function

PHP Array Reference Complete PHP Array Reference

Examples

The output of the array elements and the current value of the next element, then reset the internal array pointer to the first element in the array:

<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");

echo current($people) . "<br>";
echo next($people) . "<br>";

echo reset($people);
?>

Running instance »

Definition and Usage

reset () function in the internal pointer to the first element of the array, and output.

Related methods:

  • Current () - Returns the value of the current element in the array.
  • End () - the internal pointer to the last element in the array, and output.
  • Next () - the internal pointer to the next element in the array, and outputs.
  • the PREV () - the internal pointer to the last element of the array, and output.
  • the each () - Returns the current element's key names and values, and the internal pointer moves forward.

grammar

reset( array )

参数 描述
array 必需。规定要使用的数组。

technical details

return value: If successful, then the value of the first element of the array is returned, if the array is empty, returns FALSE.
PHP version: 4+


More examples

Example 1

All relevant presentation methods:

<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");

echo current($people) . "<br>"; // The current element is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
echo current($people) . "<br>"; // Now the current element is Joe
echo prev($people) . "<br>"; // The previous element of Joe is Peter
echo end($people) . "<br>"; // The last element is Cleveland
echo prev($people) . "<br>"; // The previous element of Cleveland is Glenn
echo current($people) . "<br>"; // Now the current element is Glenn
echo reset($people) . "<br>"; // Moves the internal pointer to the first element of the array, which is Peter
echo next($people) . "<br>"; // 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
?>

Running instance »


PHP Array Reference Complete PHP Array Reference