If your array contains values in consecutive numeric order – array_slice
would be the simplest approach:
$result = array_slice($ar, 2, 3);
print_r($result);
The output:
Array
(
[C] => 3
[D] => 4
[E] => 5
)
———-
To print the result as key/value pairs:
foreach (array_slice($ar, 2,3) as $k => $v) {
echo "$k => $v" . PHP_EOL;
}
The output:
C => 3
D => 4
E => 5
solved i want to echo the values from index 3 to 5 in an associative array, couldn’s figure it out,