如何访问 stdClass 的 stdClass 数组中的成员?
我想知道如何访问 stdObjects 的 stdObect 数组。我有一个数组,在使用 print_r()
打印时看起来像这样:
stdClass Object ([item] => Array(
[0] => stdClass Object([id] => 0 [name] => Peter)
[1] => stdClass Object([id] => 1 [name] => Jack)))
如何访问名称字段?如果它不是一个数组,我可以通过调用该字段来获取属性,例如:
$client = new SoapClient("http://url.to.my.wsdl", array("trace" => 0));
echo $client->GetPerson()->name;
但是当使用数组时,这不起作用:
$client = new SoapClient("http://url.to.my.wsdl", array("trace" => 0));
$persons = $client->GetPersons();
echo $persons[0]->name;
这只会给我错误:
Fatal error: Cannot use object of type stdClass as array
I am wondering how I can access a stdObect array of stdObjects. I have an array that looks something like this when printing it with print_r()
:
stdClass Object ([item] => Array(
[0] => stdClass Object([id] => 0 [name] => Peter)
[1] => stdClass Object([id] => 1 [name] => Jack)))
How can I access the name field? If it not was an array, I could get the attributes by calling the field, like:
$client = new SoapClient("http://url.to.my.wsdl", array("trace" => 0));
echo $client->GetPerson()->name;
But when using arrays, this does not work:
$client = new SoapClient("http://url.to.my.wsdl", array("trace" => 0));
$persons = $client->GetPersons();
echo $persons[0]->name;
That just gives me the error:
Fatal error: Cannot use object of type stdClass as array
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据你的 print_r 信息,试试
According to your print_r info ,just try
试试这个:
try this:
该数组包含在字段
item
内。The array is contained inside the field
item
.