I'm really struggling with making this work, I have looked at guides but I can't seem to see the difference between mine and theirs, other than how the array is laid out.
<?php
$country = array('England' => "London", 'Scotland' => "Edinburgh", 'France' => "Paris");
foreach ($capitals as $country=>$capital) {
echo "The capital of $country is $capital";
}
?>
All I want it to do is say the country and its capital.
error code --
Notice: Undefined variable: capitals in C:\xampp\htdocs\foreach.php on line 4
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\foreach.php on line 4
Thanks in advance.
$capitals? I don't see it anywhere. I guess you want to use$capitals = array(...);instead of$country = array(...);.Undefined variable: capitalsdon't you understand? (that's a serious question, I'm not being condescending, just don't know how to phrase it better). It gives a pretty clear signal what is wrong, namely that you are trying to access a variable that doesn't exist.