我喜欢从下面的数组中获取要打印的每个stdClass对象[name]的名称,我尝试了下面的数组代码,但我只得到一个结果,请建议我如何获取每个数组的名称。
$result array as :
stdClass Object
(
[return] => Array
(
[0] => stdClass Object
(
[mode] => BASIC
[name] => test
[state] => NOT_RUNNING
[trainingMode] =>
[type] => OUTBOUND
)
[1] => stdClass Object
(
[mode] => BASIC
[name] => test1
[state] => NOT_RUNNING
[trainingMode] =>
[type] => OUTBOUND
)
[2] => stdClass Object
(
[description] => description
[mode] => BASIC
[name] => New Campaign from CRM
[state] => RUNNING
[trainingMode] =>
[type] => OUTBOUND
)
)
)
我尝试使用此代码,但只能输出一个
$i=0;
foreach($result as $object){
echo $object[$i]->name."\n";
$i=$i+1;
}
答案 0 :(得分:1)
你不需要柜台。
<?php
foreach($result as $object){
echo $object->name."\n";
}
答案 1 :(得分:1)
怎么样?
foreach($result as $object) {
foreach ($object as $item) {
echo $item->name, "\n";
}
}