duancheng8000 2017-10-05 16:51
浏览 19
已采纳

按键值在数组中进行多维搜索[PHP]

I am trying to find the url value using itag value in the array. I want to find the url value in the array with the itag value 18 (itag=18).

PHP Code:

<?php
$videoId = "EJOnwF8mgXc";
parse_str(file_get_contents("http://youtube.com/get_video_info?video_id=" . 
$videoId), $info);
$streams = $info['url_encoded_fmt_stream_map'];
$streams = explode(',', $streams);
foreach ($streams as $stream) {
parse_str($stream, $data);
print_r($data);
}

Output Sample: https://gist.githubusercontent.com/ahmethakanbesel/30cb351501588f2e5c5d961aefb48aa0/raw/a29b2f016b39d452602b1f8aca5bbd6823886bb4/array.txt

  • 写回答

1条回答 默认 最新

  • dpwle46882 2017-10-05 19:22
    关注

    A simple "if" statement will do :

    <?php
    $videoId = "EJOnwF8mgXc";
    parse_str(file_get_contents("http://youtube.com/get_video_info?video_id=" . 
    $videoId), $info);
    $streams = $info['url_encoded_fmt_stream_map'];
    $streams = explode(',', $streams);
    foreach ($streams as $stream) {
        parse_str($stream, $data);
        if($data['itag'] == 18){
            echo $data['url'];
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效