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 equal to 5, then get all, else the last 5.
I tried the PHP functions last() and array_pop() but they return only the last element.
You need
array_slice, which does exactly this.-5means “start at five elements before the end of the array”.