doushi9376 2017-03-21 13:02
浏览 102
已采纳

使用PHP获取最后两项json_decode结果

The following code works and pulls all the images in from the json file.

    $content = file_get_contents('URL');
    $json = json_decode($content, true);

    foreach($json['format'] as $item) {
            echo '<img src="' . $item['picture'] . '">';
    }

Is there a way that I can have it only grab the last two pictures.

  • 写回答

4条回答 默认 最新

  • dongyi1939 2017-03-21 13:06
    关注

    Yes, there is a way.

    $result = array_slice($json['format'], -2);
    

    Have a try.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?