PHP: Reverse a JSON array

Can someone help me with some PHP please.

The original code ~works, but the output is in the wrong order. So I need to REVERSE the sequence/order of the JSON array.

<?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"];

I can find where put the array_reverse

Upvotes: -2

Views: 1016

Answers (1)

Darshana
Darshana

Reputation: 41

$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>";

Upvotes: 0

Related Questions