Find if some words in array value are in same array php I have to find where a given string is in my multidimensional array.
So this is my array

$input = array(array('time' =&gt; '18:31:00', 'artist' =&gt; 'LUIS RODRIGUEZ &amp; DEN HARROW'), array('time' =&gt; '18:32:00', 'artist' =&gt; 'J BALVIN'), array('time' =&gt; '18:33:00', 'artist' =&gt; 'THE BLACK EYED PEAS FT J BALVIN'), array('time' =&gt; '18:34:00', 'artist' =&gt; 'THE BLACK EYED PEAS FT J BALVIN'), array('time' =&gt; '18:35:00', 'artist' =&gt; 'J BALVIN'));


I have to find at what time I can find this

$artista_inserito = 'THE BLACK EYED PEAS FT J BALVIN';


So I use a function to delimiter my array and even string

function multiexplode($delimiters, $string)
{

    $ready = str_replace($delimiters, $delimiters[0], $string);
    $launch = explode($delimiters[0], $ready);
    return  $launch;
}

// array with string delimeter
$array_delimiter_artisti = array(' FEAT ', ' feat ', ' FT ', ' ft ', ' + ', ' AND ', ' and ', ' E ', ' e ', ' VS ', ' vs ', ' FEAT. ', ' feat. ', ' FT. ', ' ft. ', ' VS. ', ' vs. ', ' , ', ' &amp; ');

// I split the current artist
$artisti_inseriti = multiexplode($array_delimiter_artisti, $artista_inserito);


So I search the given string un my array

foreach ($input as $split) {
    $time = $split['time'];
    $artist = $split['artist'];
    $lista_artisti = multiexplode($array_delimiter_artisti, $artist);

    foreach ($lista_artisti as $nuovo) {
        $artista_split = $nuovo;

        // copy all new data in new array
        $nuovo_array_dati[] = array('time' =&gt; $time, 'artist' =&gt; $artista_split);
    }
}

foreach ($nuovo_array_dati as $controllo) {
    $time = $controllo['time'];
    $artist = $controllo['artist'];

    foreach ($artisti_inseriti as $trova_artista) {
        $artista_singolo = $trova_artista;



        foreach ($controllo as $index =&gt; $a) {
            if (strstr($a, $artista_singolo)) {
                // now I can print where I found the given string $artista_inserito
                echo "$artista_singolo  is at $time ";

            }
        }
    }
}


So this is my output

J BALVIN is at 18:32:00 
THE BLACK EYED PEAS is at 18:33:00 
J BALVIN is at 18:33:00 
THE BLACK EYED PEAS is at 18:34:00 
J BALVIN is at 18:34:00 
J BALVIN is at 18:35:00 


Can I improve this?
Thanks
I have a bias toward regex because I'm generally comfortable with most techniques, so I'll recommend condensing your array of delimiters into a single regex pattern and employ preg_split() to execute the explosion.

After splitting the search string into its separate artists, I am flipping the values &amp; keys to optimize the lookup for later use in the nested loop.

Then as you iterate the haystack of artist times, you can re-use the splitting pattern, then iterate each individual artist and store the desired data for qualifying rows.

Code: (Demo)

$fullArtistTimes = [
    ['time' =&gt; '18:31:00', 'artist' =&gt; 'LUIS RODRIGUEZ &amp; DEN HARROW'],
    ['time' =&gt; '18:32:00', 'artist' =&gt; 'J BALVIN'],
    ['time' =&gt; '18:33:00', 'artist' =&gt; 'THE BLACK EYED PEAS FT J BALVIN'],
    ['time' =&gt; '18:34:00', 'artist' =&gt; 'THE BLACK EYED PEAS FT J BALVIN'],
    ['time' =&gt; '18:35:00', 'artist' =&gt; 'J BALVIN']
];

$fullArtist = 'THE BLACK EYED PEAS FT J BALVIN';

$artistDelimiters = '~ (?:[+e,&amp;]|and|f(?:ea)?t\.?|vs\.?) ~i';

$artists = array_flip(preg_split($artistDelimiters, $fullArtist));

$result = [];
foreach ($fullArtistTimes as $row) {
    foreach (preg_split($artistDelimiters, $row['artist']) as $artist) {
        if (isset($artists[$artist])) {
            $result[] = "{$artist} is at {$row['time']}";
        }
    }
}

var_export($result);


Output:

array (
  0 =&gt; 'J BALVIN is at 18:32:00',
  1 =&gt; 'THE BLACK EYED PEAS is at 18:33:00',
  2 =&gt; 'J BALVIN is at 18:33:00',
  3 =&gt; 'THE BLACK EYED PEAS is at 18:34:00',
  4 =&gt; 'J BALVIN is at 18:34:00',
  5 =&gt; 'J BALVIN is at 18:35:00',
)


If this does not work for all of your cases, then I would need to see more test cases and your desired result before I could properly adjust my snippet.