PHP: обратный массив JSON

Может кто-нибудь помочь мне с PHP, пожалуйста.

Исходный код ~ работает, но вывод в неправильном порядке. Поэтому мне нужно ОБРАТИТЬ последовательность / порядок массива JSON.

<?php

$url = "https://api.typeform.com/XXX";

$json = file_get_contents($url);

$data = json_decode($json, true);

foreach ($data["responses"] as $item) {

if ($item["answers"]["textfield_14052468"] != '') {

$intitule = $item["answers"]["textfield_14052468"];
$description = $item["answers"]["textarea_14052495"];
$boite = $item["answers"]["textfield_14051470"];
$contact = $item["answers"]["textfield_14053600"];
$type = $item["answers"]["list_15488974_other"];
$contactmail = $item["answers"]["email_14053555"];
$madate = $item["answers"]["date_14052792"];
$file = $item["answers"]["fileupload_14052536"];
$contract = $item["answers"]["textarea_14052561"];
$web = $item["answers"]["website_14052525"];
$date_submit = $item["metadata"]["date_submit"];

Я могу найти где поставить array_reverse

-2

Решение

$json = file_get_contents($url,0,null,null);
$tmp = json_decode($json, true);    // using a temp variable for testing
$result = $tmp;
$result['data'] = array_reverse($result['data']);

foreach ($result['data'] as $event) {
echo '<div>'.$event['name'].'</div>'; //in order to display in div
0

Другие решения

$url = 'http://link.to.api'
$json = file_get_contents($url,0,null,null);
$tmp = json_decode($json, true);

$result = array_reverse($tmp);

print "<pre>";
print_r($result);
print "</pre>";
0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector