如何访问的成员stdClasses的stdClass的阵列? [英] How do I access the members in a stdClass array of stdClasses?

查看:156
本文介绍了如何访问的成员stdClasses的stdClass的阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我怎么能访问stdObjects的stdObect数组。我有一个数组与的print_r()打印时它看起来是这样的:

  stdClass的对象([项目] =>阵列(
    [0] => stdClass的对象([ID] => 0名] =>彼得)
    [1] => stdClass的对象([ID] => 1 [名] =>杰克)))

我如何可以访问name字段?如果不是是一个数组,我可以通过调用场拿到属性,如:

  $客户=新SoapClient的(HTTP://url.to.my.wsdl,阵列(跟踪= 0));
回声$客户 - > GetPerson() - GT;名;

但是,使用阵列时,这不起作用:

  $客户=新SoapClient的(HTTP://url.to.my.wsdl,阵列(跟踪= 0));
$人= $客户 - > GetPersons();
回声$人[0] - >名;

这只是给我的错误:

 致命错误:无法使用类型stdClass的对象为数组


解决方案

根据您的print_r信息,只要尝试

 回声$人士─>项目[0]  - >名

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

解决方案

According to your print_r info ,just try

echo $persons->item[0]->name

这篇关于如何访问的成员stdClasses的stdClass的阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆