echo key and value of an array without and with loop
Without a loop, just for the kicks of it...
You can either convert the array to a non-associative one, by doing:
$page = array_values($page);
And then acessing each element by it's zero-based index:
echo $page[0]; // 'index.html'echo $page[1]; // 'services.html'
Or you can use a slightly more complicated version:
$value = array_slice($page, 0, 1);echo key($value); // Homeecho current($value); // index.html$value = array_slice($page, 1, 1);echo key($value); // Serviceecho current($value); // services.html
If you must not use a loop (why?), you could use array_walk
,
function printer($v, $k) { echo "$k is at $v\n";}array_walk($page, "printer");