There is such a json , in the usual way it is convenient to use it to display one news, but in descending order, it is convenient to use it to display all news (first new ones, below the old ones).

How can this be done?

$json = json_decode($output); $json_main = $json->News; if ($_GET['action'] == 'news') { $content .= '<div class="News">'; foreach ($json_main as $item) { $content.= '<div class="New"><div class="NewsTitle"><a href="/new/'.$item->ID.'" onclick="getNewsOne('.$item->ID.');">'.$item->Title.'</a></div><div class="NewsContent">'.$item->ShortContent.'</div></div>'; } $content .= '</div>'; Show($content,'Новости'); } 

    1 answer 1

    Judging by your code after the operation $json_main = $json->News; in $ json_main there will be an array, so the function array_reverse can be applied to it.

    Ie if you need to sort the array in reverse order, you just do so

     $sorted = array_reverse($json->News);