end() function in PHP

PHPProgrammingServer Side Programming

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)."\n";
echo next($a)."\n";
echo current($a)."\n";
echo end($a)."\n";
echo current($a)."\n";
?>

Output

The following is the output −

one
two
two
six
six
raja
Published on 15-Oct-2018 12:56:36
Advertisements