Home >>PHP Array Functions >PHP end() Function

PHP end() Function

PHP end() Function

PHP end() function is used to find the last element of the given input array. It changes the internal pointer of the array to the last element and returns the value of that last element. It accepts only a single parameter $array that is the array whose last element is to be found.

Syntax:

end($array);

Parameter Values

Parameter Description
array This is a required parameter. This parameter defines the array to use.

Here is an example of end() function in PHP:

<html>
<body>
<?php
$x = array("A","B","H","I","M","A","N","Y","U");
echo current($x) . "<br>";
echo end($x);
?>
</body>
</html>
Output:
A  
U  

Example 2:

<html>
<body>
<?php
$x = array("A","B","H","I","M","A","N","Y","U");
echo current($x)."<br>"; // The current element is A
echo next($x)."<br>"; // The next element of A is B
echo current($x)."<br>"; // Now the current element is B
echo end($x)."<br>"; // The last element is U
echo current($x)."<br>"; // Now the current element is U
?>
</body>
</html>
Output:
A  
B  
B  
U  
U 	

No Sidebar ads