0

xml 出力からいくつかのデータを取得する必要があります。

[current_condition] => SimpleXMLElement Object
    (
        [observation_time] => 12:22 PM
        [temp_C] => 18
        [temp_F] => 64
        [weatherCode] => 116
        [weatherIconUrl] => SimpleXMLElement Object
            (
            )

        [weatherDesc] => SimpleXMLElement Object
            (
            )

        [windspeedMiles] => 4
        [windspeedKmph] => 7
        [winddirDegree] => 180
        [winddir16Point] => S
        [precipMM] => 0.1
        [humidity] => 52
        [visibility] => 10
        [pressure] => 1023
        [cloudcover] => 50
    )

[weather] => Array
    (
        [0] => SimpleXMLElement Object
            (
                [date] => 2013-04-23
                [tempMaxC] => 20
                [tempMaxF] => 69
                [tempMinC] => 7
                [tempMinF] => 44
                [windspeedMiles] => 5
                [windspeedKmph] => 8
                [winddirection] => SSW
                [winddir16Point] => SSW
                [winddirDegree] => 210
                [weatherCode] => 113
                [weatherIconUrl] => SimpleXMLElement Object
                    (
                    )

                [weatherDesc] => SimpleXMLElement Object
                    (
                    )

                [precipMM] => 0.7
            )

        [1] => SimpleXMLElement Object
            (
                [date] => 2013-04-24
                [tempMaxC] => 25
                [tempMaxF] => 76
                [tempMinC] => 8
                [tempMinF] => 46
                [windspeedMiles] => 3
                [windspeedKmph] => 5
                [winddirection] => NNE
                [winddir16Point] => NNE
                [winddirDegree] => 24
                [weatherCode] => 113
                [weatherIconUrl] => SimpleXMLElement Object
                    (
                    )

                [weatherDesc] => SimpleXMLElement Object
                    (
                    )

                [precipMM] => 0.3
            )

    )

使用しています

printf("<p>Current temperature %s and code %s</p>", 
    $xml->current_condition->temp_C, $xml->current_condition->weatherCode);

温度と天気コードを出力し、正常に動作しており、出力しています:

Current temperature 18 and code 116

Weather Array [0] および配列 [1] から TempMaxC と TempMinC を取得するにはどうすればよいですか

ありがとう

4

1 に答える 1

0

次を使用できますforeach

foreach($xml->weather as $weatherObj) {
   echo "<h2>Weather on {$weatherObj->date}</h2>";
   echo "<ul>";
   echo "<li>Max temp: {$weatherObj->tempMaxC}</li>";
   echo "<li>Min temp: {$weatherObj->tempMinC}</li>";
   echo "</ul>";
}
于 2013-04-23T12:41:21.193 に答える