Php 如何搜索数组以查找包含特定值的数组?
我确信这非常简单,但我对数组还不熟悉,我正在使用TMDBAPI和PHP。我想知道导演的名字。 这是阵列的缩短版本:Php 如何搜索数组以查找包含特定值的数组?,php,arrays,json,api,Php,Arrays,Json,Api,我确信这非常简单,但我对数组还不熟悉,我正在使用TMDBAPI和PHP。我想知道导演的名字。 这是阵列的缩短版本: Array ( [credits] => Array ( [crew] => Array ( [0] => Array ( [id] => 40243
Array
(
[credits] => Array
(
[crew] => Array
(
[0] => Array
(
[id] => 40243
[name] => Gil Junger
[department] => Directing
[job] => Director
[profile_path] =>
)
)
)
)
我已经做到了这一点:
$film_query = file_get_contents("http://api.themoviedb.org/3/movie/".$film_id."?api_key=".$key."&append_to_response=credits,images&json_callback=?");
$film_json = json_decode($film_query, true);
$director = $film_json['credits']['crew']['job'];
非常感谢你的帮助 这个怎么样:
function getDirector(array $crew) {
foreach($crew as $person) {
if($person['job'] == 'Director') {
return $person['name'];
}
}
return null;
}
在代码中,您可以将$film_json['credits']['crew']
作为$crew
参数传递