-3

在这个数组中,我想从 value 中找到单词“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');
4

2 回答 2

2

这可以通过preg_greponeliner 来完成:

print_r(preg_grep('/in/', $londonCalling));
于 2018-12-16T12:05:48.973 回答
0

或者 array_filter

$res = array_filter($londonCalling , function($e){
    return strpos($e, 'in') !== false;
});

print_r([$res]);
于 2018-12-16T12:12:11.483 回答