當我print_r($ a);輸出如下:如何在PHP中對數組進行foreach?
Array
(
[0] => stdClass Object
(
[tid] => 3
[vid] => 1
[name] => cPanel
[description] =>
[format] =>
[weight] => 0
[depth] => 0
[parents] => Array
(
[0] => 0
)
)
[1] => stdClass Object
(
[tid] => 4
[vid] => 1
[name] => whm
[description] =>
[format] =>
[weight] => 0
[depth] => 0
[parents] => Array
(
[0] => 0
)
)
[2] => stdClass Object
(
[tid] => 5
[vid] => 1
[name] => test
[description] =>
[format] =>
[weight] => 0
[depth] => 0
[parents] => Array
(
[0] => 0
)
)
)
數組鍵可能會增加。現在,我想輸出數組的所有name'
的值。 當我使用下面的代碼。它顯示我一個錯誤。
foreach($a as $a->name){
echo a->name;
}
請*總是*指出你得到什麼* *錯誤究竟。 – 2011-05-26 13:40:05
有趣的是,在海報提交之前,這種類型的問題實際上是如何得到一堆答案的。大聲笑! :o) – stefgosselin 2011-05-26 13:43:30