I have an array $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34);
. How can i get (echo) all names and correspondi开发者_开发技巧ng ages in a single instance (like foreach $value as $value
)?? The array may have more data than shown here.
foreach ($ages as $name => $age) {
echo "$name = $age\n";
}
u have a lot options
like
print_r
print_r($array)
var_dump , foreach
print_r($array);
or
var_dump($array)
foreach ($ages as $key => $value) {
echo $key . "'s age is " . $value . "<br />";
}
精彩评论