I’ve to seek out the place a given string is in my multidimensional array.
So that is my array
$enter = array(array('time' => '18:31:00', 'artist' => 'LUIS RODRIGUEZ & DEN HARROW'), array('time' => '18:32:00', 'artist' => 'J BALVIN'), array('time' => '18:33:00', 'artist' => 'THE BLACK EYED PEAS FT J BALVIN'), array('time' => '18:34:00', 'artist' => 'THE BLACK EYED PEAS FT J BALVIN'), array('time' => '18:35:00', 'artist' => 'J BALVIN'));
I’ve to seek out at what time I can discover this
$artista_inserito = 'THE BLACK EYED PEAS FT J BALVIN';
So I take advantage of a operate to delimiter my array and even string
operate multiexplode($delimiters, $string)
{
$prepared = str_replace($delimiters, $delimiters[0], $string);
$launch = explode($delimiters[0], $prepared);
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. ', ' , ', ' & ');
// I break up the present artist
$artisti_inseriti = multiexplode($array_delimiter_artisti, $artista_inserito);
So I search the given string un my array
foreach ($enter as $break up) {
$time = $break up['time'];
$artist = $break up['artist'];
$lista_artisti = multiexplode($array_delimiter_artisti, $artist);
foreach ($lista_artisti as $nuovo) {
$artista_split = $nuovo;
// copy all new knowledge in new array
$nuovo_array_dati[] = array('time' => $time, 'artist' => $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 => $a) {
if (strstr($a, $artista_singolo)) {
// now I can print the place I discovered the given string $artista_inserito
echo "$artista_singolo is at $time ";
}
}
}
}
So that 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 enhance this?
Thanks