End()

  • Support PHP 4, PHP 5
  • Short description: sets the internal pointer of an array to its last element.
  • Requirements.

Description

The end() function sets an internal array pointer to the last element and returns its value.

Similar functions

  • current()
  • each()
  • prev()
  • reset()
  • next()

Example

php
echo end([
'apple',
'banana',
'cranberry',
]); // prints cranberry
php
$a = [];
$a[1] = 1;
$a[0] = 0;
echo end($a); // prints 0

Parameters

# Type Description
1 array The name of the array to work with.

Return values

Returns the value of the last element or false for an empty array.

Differences from earlier versions

None

Newsletter

Nejlepsi tipy a triky o PHP do Vaseho e-mailu. Clanky a novinky nejen ze sveta PHP a programovani.