PHP get the last 3 elements of an associative array while preserving the keys?

If you want to preserve key, you can pass in true as the fourth argument:

array_slice($a, -3, 3, true);

Leave a Comment