echo key and value of an array without and with loop

esafwan picture esafwan · Aug 4, 2010 · Viewed 119.7k times · Source

This is an array i have

<?php
$page['Home']='index.html';
$page['Service']='services.html';
?>

How do i get to echo something like this for individual one like

Home is at index.html

and again how can i do this through a loop and echo all?

Answer

Mchl picture Mchl · Aug 4, 2010
foreach($page as $key => $value) {
  echo "$key is at $value";
}

For 'without loop' version I'll just ask "why?"