end

(PHP 4, PHP 5, PHP 7, PHP 8)

endSet the internal pointer of an array to its last element

Опис

end(array|object &$array): mixed

end() advances array's internal pointer to the last element, and returns its value.

Параметри

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.

Значення, що повертаються

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

Журнал змін

Версія Опис
8.1.0 Виклик цієї функції для об'єктів є застарілим. Краще перетворити object в array, застосувавши get_mangled_object_vars(), або використати методи класу, який імплементує Iterator, наприклад ArrayIterator.
7.4.0 Примірники класів SPL тепер розглядаються як порожні об'єкти, які не мають властивостей, замість виклику метода інтерфейсу Iterator з такою ж назвою, як і в цієї функції.

Приклади

Приклад #1 end() example

<?php

$fruits
= array('apple', 'banana', 'cranberry');
echo
end($fruits); // cranberry

?>

Прогляньте також

  • current() - Return the current element in an array
  • each() - Return the current key and value pair from an array and advance the array cursor
  • prev() - Rewind the internal array pointer
  • reset() - Встановлює внутрішній вказівних масиву на його перший елемент
  • next() - Advance the internal pointer of an array
  • array_key_last() - Gets the last key of an array