• PHP Video Tutorials

PHP - Function end()



Syntax

end ( $array );

Definition and Usage

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

Parameters

Sr.No Parameter & Description
1

array(Required)

It specifies an array

Return Value

It 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
Advertisements