PHP extract part from array keeping previous keys
With array_slice, the original array is not modified:
$levels = array('a' => 1, 'b' =>2, 'c' => 3, 'd' => 4, 'f' => 5, 'g' => 6);$firstLevels = array_slice($levels, 0, 5, true);// count($levels) is 6, count($firstLevels) 5