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 );

Definition and Usage

The end() function moves the array's internal pointer 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 you must pass an actual variable, not an array returned by a function, because only actual 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