0

对于这个数组

stdClass Object
(
    [YearsResult] => stdClass Object
        (
            [years] => stdClass Object
                (
                    [year] => Array
                        (
                            [0] => 2013
                            [1] => 2012
                            [2] => 2011
                            [3] => 2010
                            [4] => 2009
                            [5] => 2008
                            [6] => 2007
                            [7] => 2006
                            [8] => 2005
                            [9] => 2004
                            [10] => 2003
                            [11] => 2002
                            [12] => 2001
                            [13] => 2000
                            [14] => 1999
                            [15] => 1998
                        )

                )

        )

)

运行 foreach 循环以获取年份值的正确方法是什么?我已经尝试了我能找到/想到的所有可能的方法,我最后一次尝试是

foreach ($result->YearsResult->years->year as $test) {
     echo $test->year;
}

什么都不返回。

4

1 回答 1

0

$result->YearsResult->years->year 是你想要的数组。所以 $test 是数组元素。

echo $test;
于 2012-08-27T19:59:44.520 回答