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

按键值在数组中进行多维搜索[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

我试图在数组中使用itag值找到url值。 我想找到url值in 具有itag值18(itag = 18)的数组。 p>

PHP代码: p>

 &lt;?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); 
} 
  code>   pre> 
 
 

输出样本: https: //gist.githubusercontent.com/ahmethakanbesel/30cb351501588f2e5c5d961aefb48aa0/raw/a29b2f016b39d452602b1f8aca5bbd6823886bb4/array.txt p> div>

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'];
    }
}