2012-08-27 160 views
0

對於這個數組的foreach循環對象

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

返回什麼。

回答

0

$ result-> YearsResult-> years->今年是你想要的陣列。所以$ test是數組元素。

echo $test; 
+0

太謝謝你了。 – Diane