PHP get the last 3 elements of an associative array while preserving the keys? May 23, 2023 by Tarik If you want to preserve key, you can pass in true as the fourth argument: array_slice($a, -3, 3, true);