-3

in this array, I want to find word "in" from value and make new array from that songs including number (key) songs from album.

$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');

2 Answers2

2

This can be done with preg_grep oneliner:

print_r(preg_grep('/in/', $londonCalling));
u_mulder
  • 54,101
  • 5
  • 48
  • 64
0

alternatively array_filter

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

print_r([$res]);
Redr01d
  • 392
  • 2
  • 12