English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP end() Function Usage and Example

PHP Array Function Manual

 The end() function returns the last element of the array

Syntax

end(array $array);

Definition and Usage

The end() function advances the internal pointer of the array to the last element and returns its value.

Parameter

Serial NumberParameters and Description
1

array(Required)

It specifies an array that is passed by reference, because it will be modified by this function. This means that you must pass a real variable, not an array returned by the function, because only real variables can be passed by reference.

Return value

 Returns the value of the last element, or FALSE if the array is empty.

Online example

<?php
   $transport = array('foot', 'bike', 'car', 'plane');
   $mode = current($transport); 
   print "$mode<br />";
   
   $mode = next($transport);  
   print "$mode<br />";
   
   $mode = current($transport);
   print "$mode<br />";
   
   $mode = prev($transport);  
   print "$mode<br />";
   
   $mode = end($transport);   
   print "$mode<br />";
   
   $mode = current($transport); 
   print "$mode<br />";
?>
Test and see‹/›

Output result:

foot
bike
bike
foot
plane
plane

   PHP Array Function Manual