0

For this array

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
                        )

                )

        )

)

What is the correct method for running a foreach loop to get the year values? I have tried every conceivable method I can find/think, and my last attempt was

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

which returns nothing.

j0k
  • 22,600
  • 28
  • 79
  • 90
Diane
  • 103
  • 2

1 Answers1

0

$result->YearsResult->years->year is the array you want. So $test is the array element.

echo $test;
Philippe Boissonneault
  • 3,949
  • 3
  • 26
  • 33