Частично отрабатывает код, в чём причина?

Пили, пили и не допили API Яндекс погоды, суть в следующем: утро-день, день-вечер и вечер-ночь выводит отлично (почему через "-", просто в html выводятся два прогноза), а вот ночь-утро ни в какую, ни иконку погоды, ни температуру, как будто не видит. Меня и время (с МСК на местное) и интервал вывод из if ничего не помогает, спасайте!!!!
Вывод в 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 ;
$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;}
	
	$time = date("H");

    if($time > 6 && $time < 12) {$i = 1;}
    if($time > 12 && $time < 18) {$i = 2;}
    if($time > 18 && $time < 24) {$i = 3;}
	if($time > 24 && $time < 6) {$i = 0;}

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

$out = array();
$counter = 0 ;

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

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

   $time = date("H");

    if($time > 6 && $time < 12) {$i = 2;}
    if($time > 12 && $time < 18) {$i = 3;}
    if($time > 18 && $time < 24) {$i = 0;}
	if($time > 24 && $time < 6) {$i = 1;}

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

Даже были мысли, что мб у яндекса просто нет погоды на сл. день и поэтому ему у меня сайте взяться не откуда, но нет https://pogoda.yandex.ru/novosibirsk/ всё отлично выводится.....
(P.S. код не самый читабельный, просто пилил под себя не обессудьте)
  • Вопрос задан
  • 326 просмотров
Пригласить эксперта
Ответы на вопрос 1
код не самый читабельный, просто пилил под себя не обессудьте

ну так ты приведи код в порядок, в читабельный так сказать вид, переменные назови по-людски, а там глядишь и понимать что-то начнешь.

а то уже который по счету вопрос с этим кодом тут.

дебаггер еще попробуй, резко проясняет ход событий.
Ответ написан
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы