在此数组中,我想从值中找到单词“ in”,然后从该歌曲(包括专辑中的数字(关键)歌曲)中新建一个数组。
$londonCalling = array(
'song-01' => 'London Calling',
'song-02' => 'Brand New Cadillac',
'song-03' => 'Jimmy Jazz',
'song-04' => 'Hateful',
'song-05' => 'Rudie Cant Fail',
'song-06' => 'Spanish Bombs',
'song-07' => 'The Right Profile',
'song-08' => 'Lost in the Supermarket',
'song-09' => 'Clampdown',
'song-10' => 'The Guns of Brixton',
'song-11' => 'Wrong Em Boyo',
'song-12' => 'Death or Glory',
'song-13' => 'Koka Kola',
'song-14' => 'The Card Cheat',
'song-15' => 'Lovers Rock',
'song-16' => 'Four Horsemen',
'song-17' => 'Im Not Down',
'song-18' => 'Revolution Rock',
'song-19' => 'Train in Vain');
答案 0 :(得分:2)
这可以通过preg_grep
oneliner来完成:
print_r(preg_grep('/in/', $londonCalling));
答案 1 :(得分:0)
或者array_filter
$res = array_filter($londonCalling , function($e){
return strpos($e, 'in') !== false;
});
print_r([$res]);