PHP soap请求访问对象中的数组

时间:2014-08-28 08:19:49

标签: php soap

我希望在我的肥皂请求中返回的这个对象中回忆所有这些年 我不知道如何访问数组来迭代这些年份 输出来自print_r($response_year);

stdClass Object
(
    [GetVehicleYearsResult] => stdClass Object
        (
            [Errors] =>   
            [Years] => stdClass Object  
                (
                    [int] => Array
                        (
                            [0] => 2015
                            [1] => 2014
                            [2] => 2013
                            [3] => 2012
                            [4] => 2011
                            [5] => 2010
                            [6] => 2009
                            [7] => 2008
                            [8] => 2007
                            [9] => 2006
                            [10] => 2005
                            [11] => 2004
                            [12] => 2003
                            [13] => 2002
                            [14] => 2001
                            [15] => 2000
                            [16] => 1999
                            [17] => 1998
                            [18] => 1997
                            [19] => 1996
                            [20] => 1995
                            [21] => 1994
                        )    
                )    
        )    
)

1 个答案:

答案 0 :(得分:0)

这将列出年份。

foreach ($response_year->GetVehicleYearsResult->Years->int as $year) {
  echo $year;
}

可以通过$array = $response_year->GetVehicleYearsResult->Years->int;访问该数组。

简单地记住这样的结构:

  • 在'对象'之后,使用->
  • 在'数组'之后,使用[$key]