当我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