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
It's simple use array_slice and count()
count()
$arraylength=count($array); if($arraylength >5) $output_array= array_slice($array,($arraylength-5),$arraylength); else $output_array=$array;