array_last()
Polyfill for array_last() added in PHP 8.5.
Returns the last element of an array.
No Hooks.
Returns
Mixed|null. The last element of the array, or null if the array is empty.
Usage
array_last( $array );
- $array(array) (required)
- The array to get the last element from.
Changelog
| Since 6.9.0 | Introduced. |
array_last() array last code WP 6.9
function array_last( array $array ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound
if ( empty( $array ) ) {
return null;
}
return $array[ array_key_last( $array ) ];
}