How can I get the last 5 elements of a PHP array?
My array is dynamically generated by a MySQL query result. The length is not fixed. If the length is smaller or equ
You need array_slice, which does exactly this.
$items = array_slice($items, -5);
-5 means "start at five elements before the end of the array".
-5