【发布时间】:2017-02-12 05:25:36
【问题描述】:
我有一个像下面这样的对象
stdClass Object
(
[0] => stdClass Object
(
[className] => stdClass Object
(
[attribute] => stdClass Object
(
[name] => Aabir Hussain
[phone] => 9555555985
[email] => aabir@gmail.com
[create_on] => 12-10-2016 12:12:12
[status] => Active
)
[validationMessage] => stdClass Object
(
[name] => no_error
[phone] => no_error
[email] => Email Already Taken, Please Choose Another One
[create_on] => no_error
[status] => no_error
)
[scenario] => create
)
)
)
我想在不使用 foreach 或 for 循环的情况下获取名称的值
我尝试过this link,他们给出了不同的方法来从如下所示的对象中获取值。但没有什么对我有用。
print_r($arrayMultiIndex[0]); //not working because it is not an array;
print_r($arrayMultiIndex{0}); //not working
print_r($arrayMultiIndex->0); //not working
我使用的是 PHP 7.0.9
编辑
print_r($arrayMultiIndex->{0}); //also not working or
echo $arrayMultiIndex->{0}->className->attribute->name //not working
为 Php Fiddle 编辑 php fiddle link
【问题讨论】:
-
试试这个属性名
echo $arrayMultiIndex->{0}->className->attribute->name。 -
print_r($arrayMultiIndex->{0}); //不工作
-
你需要一个配额:
echo $arrayMultiIndex->{'0'}->className->attribute->name -
你的意思是这样 echo $arrayMultiIndex->{'0'}->className->attribute->name; .它也不起作用。给我这样的错误通知:未定义的属性:/opt/lampp/htdocs/practice/techgig_practice.php 中的 stdClass::$0 在第 116 行
-
制作一个小提琴以便更好地检查......