end

Set the internal pointer of an array to its last element

Syntax

end ( array &$array ) : mixed

Parameters

array

The array. This array is passed by reference because it is modified by the function. This means you must pass it a real variable and not a function returning an array because only actual variables may be passed by reference.

Return

Returns the value of the last element or FALSE for empty array.

Examples

1

<?

$array = array('one', 'two', 'three', 'four');

$return = end($array);

echo $return;

?>
four

2

<?

$array = array();

$return = end($array);

var_export($return);

?>
false

3

<?

$array = array();
$array[0] = 'one';
$array[1] = 'two';
$array[2] = 'three';
$array[3] = 'four';

$return = end($array);

echo $return;

?>
four

4

<?

$array = array();
$array[3] = 'four';
$array[2] = 'three';
$array[1] = 'two';
$array[0] = 'one';

$return = end($array);

echo $return;

?>
one

Internal

current

next

prev

reset

External

PHP

Home Menu