如何访问对象内的数组?

时间:2014-11-26 14:05:01

标签: php arrays

我已经通过WSLD连接到SOAP并获得一个对象,其中包含数据的数组。

以下是 print_r 的结果:

stdClass Object
(
    [GetCommonInfoMkdResult] => stdClass Object
        (
            [Municipals] => stdClass Object
                (
                    [MunInion] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [MKD] => stdClass Object
                                        (
                                            [TotalCount] => 473
                                            [TotalArea] => 1419701.74
                                        )

                                    [Inhabitants] => stdClass Object
                                        (
                                            [TotalCount] => 45919
                                        )

                                    ...

                                    [Name] => город-курорт Ессентуки
                                )
so on...

var_dump

的相同对象
object(stdClass)[5]
  public 'GetCommonInfoMkdResult' => 
    object(stdClass)[6]
      public 'Municipals' => 
        object(stdClass)[7]
          public 'MunInion' => 
            array (size=35)
              ...
      public 'Result' => 
        object(stdClass)[358]

我如何才能访问 MunInion 数组?

1 个答案:

答案 0 :(得分:1)

使用以下方式访问它:

$obj = YOUR_WSDL_OBJECT;
$MunicipalsArray = $obj->GetCommonInfoMkdResult->Municipals->MunInion;

或某个字段:

$TotalCount = $obj->GetCommonInfoMkdResult->Municipals->MunInion[0]->MKD->TotalCount;