【问题标题】:Foreach loop from stdClass object来自 stdClass 对象的 Foreach 循环
【发布时间】:2012-08-27 19:52:44
【问题描述】:

对于这个数组

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;
}

什么都不返回。

【问题讨论】:

    标签: foreach stdclass


    【解决方案1】:

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

    echo $test;
    

    【讨论】:

      猜你喜欢
      • 2010-10-31
      • 1970-01-01
      • 2013-06-23
      • 2012-04-05
      • 1970-01-01
      • 1970-01-01
      • 2012-01-03
      • 2021-01-19
      • 1970-01-01
      相关资源
      最近更新 更多