douzhangbao2187 2017-06-08 19:51
浏览 35
已采纳

从公共参数排序的api获取值

How would one go about listing all the values in this api in a html table ordered by their "position24" value?

I know how to call each individual value, but I'm not sure of how to automatically load them in that order.

http://www.coincap.io/front

  • 写回答

1条回答 默认 最新

  • douwen5924 2017-06-08 20:56
    关注

    You can call your API, decode the JSON, sort it by this key and return it in a table. The following lines are a base for your solution.

    function compare($a, $b) {
        return intval($a->position24) - intval($b->position24);
    }
    
    $json = file_get_contents('http://www.coincap.io/front');
    $data = json_decode($json);
    usort($data, 'compare');
    // display $data in a table
    

    If you use classes and the compare function (compare) is in the same class as the usort-function-call you should use:

    usort($data, array($this, 'compare'));
    

    UPDATE:

    You can echo out your table by calling the attribute like this:

    foreach ($data as $row) {
        echo $row->long;
        echo $row->position24;
    }
    

    Because there are so many values, I let it up to, which one you want to display. If you need help how to build a table you find more information here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题