Latest web development tutorials

PHP end () function

PHP Array Reference Complete PHP Array Reference

Examples

Output current array element and the last element values:

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

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

Running instance »

Definition and Usage

end () function in the internal pointer to the last element in the array, and output.

Related methods:

  • Current () - Returns the value of the current element in the array.
  • 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.
  • RESET () - the internal pointer to the first element in the array, and output.
  • the each () - Returns the current element's key names and values, and the internal pointer moves forward.

grammar

end( array )

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

technical details

return value: If successful, then the value of the last element in 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