SimpleXML Help

Hey guys,

Im stuck on this bugger – My brain i losing power!!! trying to traverse this:

echo $xml->data->{time-layout}[0]->{start-valid-time}[0];

Can you see what I did wrong?

 [data] => SimpleXMLElement Object
        (
            [location] => SimpleXMLElement Object
                (
                    [location-key] => point1
                    [point] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [latitude] => 28.91
                                    [longitude] => -81.21
                                )

                        )

                )

            [moreWeatherInformation] => http://forecast.weather.gov/MapClick.php?textField1=28.91&textField2=-81.21
            [time-layout] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [time-coordinate] => local
                                    [summarization] => none
                                )

                            [layout-key] => k-p24h-n7-1
                            [start-valid-time] => Array
                                (
                                    [0] => 2011-02-25T07:00:00-05:00
                                    [1] => 2011-02-26T07:00:00-05:00
                                    [2] => 2011-02-27T07:00:00-05:00
                                    [3] => 2011-02-28T07:00:00-05:00
                                    [4] => 2011-03-01T07:00:00-05:00
                                    [5] => 2011-03-02T07:00:00-05:00
                                    [6] => 2011-03-03T07:00:00-05:00
                                )
echo $xml->data->{'time-layout'}->{'start-valid-time'};

The above should work fine. The problem is that you were trying to access a “variable property” (like variable variables) whose name was the value of, for example, time-layout (i.e. the difference between the constants time and layout!) rather than the string “time-layout”.

An example of this can be found on SimpleXML’s Basic Usage manual page (Example #3).

Oh thanks so much, this usually isn’t terribly complicated but It looked like –

Array (With special - char ) [Array ID] -> SimpleXML item, so I figured it had to be done that.

Thanks!