按键值在数组中进行多维搜索[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);
}
我试图在数组中使用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>
答
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'];
}
}