Смена погоды в зависимости от времени суток?

Подкорректировал информер API Яндекс погода и получил следующее
index.php
<div class="meteo">
         
         <?php require_once 'weather/weather.php' ;
$w_city_id = 29634;
// Идентификатор города, адрес http://weather.yandex.ru/static/cities.xml
$col = 1 ;
// количество дней, на сколько нужен прогноз
$out = get_weather_day($w_city_id, $col, $time_of_day)  ;
/*
первый параметр обязательный - индентификатор города
другие параметры необязательны
*/
?>
<?php foreach ($out as $key => $value) { ?>
<?php foreach ($value['weather'] as $key1 => $value1) { ?>
<img class="img-meteo" src="http://yandex.st/weather/1.1.78/i/icons/48x48/<?php echo $value1['image']; ?>.png" width="48" height="48" />
<p class="temperature-days"><?php echo $value1['temp_to'] ; ?>°C</p>
<?php } ?>
<?php } ?>

          <?php require_once 'weather/weather.php' ;
$w_city_id = 29634;
$col = 1 ;
$time_of_night = array(
0 => 'утро',
1 => 'день',
2 => 'вечер',
3 => 'ночь'
); // Массив времени суток
$out = get_weather_night($w_city_id, $col, $time_of_night)  ;

?>
<?php foreach ($out as $key => $value) { ?>
<?php foreach ($value['weather'] as $key1 => $value1) { ?>
<div class="night"><?php echo $value1['time_of_night']; ?>
<p class="temperature"><?php echo $value1['temp_to'] ; ?>°C</p></div>
<?php } ?>
<?php } ?>
         </div>

weather.php
<?php

 function get_weather_day ($city, $col = 1, $day_of_the_week_array = array(1 => 'пн', 2 => 'вт', 3 => 'ср', 4 => 'чт', 5 => 'пт', 6 => 'сб', 7 => 'вс'), $time_of_day = array(0 => 'утро', 1 => 'день', 2 => '', 3 => 'ночь')) {
$data_file = 'http://export.yandex.ru/weather-ng/forecasts/'.$city.'.xml';   // Загружаем файл прогноза погоды для выбранного города
$xml = simplexml_load_file($data_file); // загружаем xml файл через simple_xml




$out = array(); // Массив вывода прогноза
$counter = 0 ; // Счетчик количества дней, для которых доступен прогноз


foreach ( $xml->day as $day )  {

    if ($counter == $col) {break;}


   for ($i=2;$i<=2;$i++) {



   if($day->day_part[$i]->temperature == '') {
	   
   $get_temp_from =  $day->day_part[$i]->temperature_from;
   $get_temp_to =  $day->day_part[$i]->temperature_to;

    }  else {

    $get_temp_from = (integer)$get_temp-1 ;
    $get_temp_to = (integer)$get_temp+1 ;

    }

    if($get_temp_from>0 ) {$get_temp_from = '+'.$get_temp_from ; }
    if($get_temp_to>0 ) {$get_temp_to = '+'.$get_temp_to ; }
    $out[$counter]['weather'][$i]['temp_from'] = $get_temp_from;
    $out[$counter]['weather'][$i]['temp_to'] = $get_temp_to;
    $out[$counter]['weather'][$i]['image'] = $day->day_part[$i]->{'image-v3'};
    $out[$counter]['weather'][$i]['time_of_day'] = $time_of_day[$i] ;


} $counter++ ;
}


return $out ;

}?>

 <?php

 function get_weather_night ($city, $col = 1, $day_of_the_week_array = array(1 => 'пн', 2 => 'вт', 3 => 'ср', 4 => 'чт', 5 => 'пт', 6 => 'сб', 7 => 'вс'), $time_of_night = array(0 => 'утро', 1 => 'день', 2 => 'вечер', 3 => 'ночью')) {
$data_file = 'http://export.yandex.ru/weather-ng/forecasts/'.$city.'.xml';   // Загружаем файл прогноза погоды для выбранного города
$xml = simplexml_load_file($data_file); // загружаем xml файл через simple_xml




$out = array(); // Массив вывода прогноза
$counter = 0 ; // Счетчик количества дней, для которых доступен прогноз


foreach ( $xml->day as $day )  {

    if ($counter == $col) {break;}


   for ($i=3;$i<=3;$i++) {



   if($day->day_part[$i]->temperature == '') {
	   
   $get_temp_from =  $day->day_part[$i]->temperature_from;
   $get_temp_to =  $day->day_part[$i]->temperature_to;

    }  else {

    $get_temp_from = (integer)$get_temp-1 ;
    $get_temp_to = (integer)$get_temp+1 ;

    }

    if($get_temp_from>0 ) {$get_temp_from = '+'.$get_temp_from ; }
    if($get_temp_to>0 ) {$get_temp_to = '+'.$get_temp_to ; }
    $out[$counter]['weather'][$i]['temp_from'] = $get_temp_from;
    $out[$counter]['weather'][$i]['temp_to'] = $get_temp_to;
    $out[$counter]['weather'][$i]['image'] = $day->day_part[$i]->{'image-v3'};
    $out[$counter]['weather'][$i]['time_of_night'] = $time_of_night[$i] ;


} $counter++ ;
}


return $out ;

}?>

всё работает отлично, но ни как не могу сделать, что бы в зависимости от времени суток получившиеся:
"иконка погоды" +28°C
ночью +19°C
менялись местами, подскажите как это реализовать?
  • Вопрос задан
  • 508 просмотров
Пригласить эксперта
Ответы на вопрос 1
@We-De Автор вопроса
Яндекс API изображение и так автоматически меняет, дело не в этом. Дело в том что бы в зависимости от времени суток полностью менялось сами строки с отображением погоды.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
YCLIENTS Москва
от 200 000 до 350 000 ₽
Ведисофт Екатеринбург
от 25 000 ₽
ИТЦ Аусферр Магнитогорск
от 100 000 до 160 000 ₽
26 апр. 2024, в 18:27
200000 руб./за проект
26 апр. 2024, в 18:24
80000 руб./за проект
26 апр. 2024, в 18:00
500 руб./за проект