end() function in PHP


The end() function sets the internal pointer of an array to its last element

Syntax

end(arr)

Parameters

  • arr − The specified array

Return

The end() function returns the value of the last element in the array, on success. It returns FALSE, if the array is empty.

Example

The following is an example −

 Live Demo

<?php
$os = array('windows', 'mac', 'linux', 'solaris');
echo end($os);
?>

Output

The following is the output −

solaris

Example

Let us see another example −

 Live Demo

<?php
$a = array('one', 'two', 'three', 'four', 'five', 'six' );
echo current($a)."
"; echo next($a)."
"; echo current($a)."
"; echo end($a)."
"; echo current($a)."
"; ?>

Output

The following is the output −

one
two
two
six
six

Updated on: 23-Dec-2019

185 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements