2017-10-05 91 views
1

我正在嘗試使用數組中的itag值查找url值。 我想找到itag值爲18(itag = 18)的數組中的url值。按鍵值在數組中搜索多維[PHP]

PHP代碼:

<?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); 
} 

輸出採樣: https://gist.githubusercontent.com/ahmethakanbesel/30cb351501588f2e5c5d961aefb48aa0/raw/a29b2f016b39d452602b1f8aca5bbd6823886bb4/array.txt

+1

這裏包括相關代碼,請,而不是在GitHub上要旨。另外,請說明你所嘗試過的 - 這個問題有很多現有的解決方案,所以這不是新的。 –

+0

我無法添加輸出文本,因爲它包含很多鏈接(不允許通過stackoverflow)。 @cale_b –

+0

你想找什麼? –

回答

0

一個簡單的 「if」 語句就可以了:

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