开发者

get all values from php associative array

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 />";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜