PHP - Function end()


Advertisements


Syntax

end ( $array );

Definition and Usage

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

Parameters

Parameter Description
array Required. Specifies an array

Return Value

Returns the last element in an array.

Example

Try out following 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 />";
?> 

This will produce the following result −

foot
bike
bike
foot
plane
plane 

php_function_reference.htm