there is a json array, how do i print the values ​​in this order:

Datam - namel - namel - namel Datam - namel - namel [ {"MIGX_id":"1","datam":"2018-03-15 01:30:00","logo":"img/aside-soccer.png","namel":"АНГЛИЯ - ЧЕМПИОН-ЛИГА","command":"Вулверхэмптон - Куинз Парк Рейнджерс","koef":"1.97"}, {"MIGX_id":"2","datam":"2018-03-29 01:30:00","logo":"img/aside-soccer.png","namel":"АНГЛИЯ - ЧЕМПИОН-ЛИГА","command":"Вулверхэмптон - Куинз Парк Рейнджерс","koef":"1.97"} ] 

while at me so, but I am in a stupor something

 $array = json_decode($parent_name['vl'], true); foreach ($array as $elem){ if ($elem['datam'] >= $databegin && $elem['datam'] <= $dataend && $elem['koef'] >=1.7 && $elem['koef'] <= 2.3){ echo '<tr> <td class="flag" style="background-image: url('.$elem['logo'].');"> </td> <td class="title"> <small>'.$elem['namel'].'</small> <span class="time">'.date("hi", strtotime($elem['datam'])).'</span> <span class="fore"> Прогноз на матч <ins>'.$elem['command'].'</ins></span> </td> <td class="coeff main-coeff"> <a href=""> '.$elem['koef'].' </a> </td> </tr>'; $flag = $flag + 1; break; } } 

enter image description here

  • What is the problem then? That does not work? - Daniel
  • I did not understand the essence of the question. - teran
  • there are just 5 records with the same dates, for example, I need to group them by dates and display 1 date and for example 5 namel - Aslero

1 answer 1

You can group it like this

  $array = json_decode($parent_name['vl'], true); foreach ($array as $element) { $key = strtotime(date('Ymd 00:00:00', strtotime($element['datam']))); $result[$key][] = $element; } ksort($result); foreach ($result as $key => $value) { echo "<ul>".$value[0]['datam']; foreach ($value as $item) { echo "<li>-- ".$item['namel']."</li>"; } echo "</ul>"; } 
  • did as you showed, displays it like this, without grouping, the picture in question - Aslero
  • Try replacing this line here $ result [strtotime ($ element ['datam'])] [] = $ element; on $ result [date ('Ymd', strtotime ($ element ['datam']))] [] = $ element; - Xaku
  • thanks worked - Aslero