-2

有人可以帮我一些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的放置位置

4

2 回答 2

1
$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
于 2016-01-18T09:18:22.803 回答
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>";
于 2018-01-18T09:36:39.450 回答