Skip to content
Advertisement

echo key and value of an array without and with loop

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?

Advertisement

Answer

foreach($page as $key => $value) {
  echo "$key is at $value";
}

For ‘without loop’ version I’ll just ask “why?”

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement