PHP Find Array Index value in multi-line array



PHP Snippet 1:

$array1['Alpha']="New York,Los Angeles,Washington";
$array1['Beta']="New York,Los Angeles,Honolulu";
$array1['Gamma']="New York,Los Angeles,Washington";

$returnData = [];
foreach ($array1 as $k => $val)
{
 $datas = explode(",",$val);
    if(in_array('Washington', $datas) ){
        $returnData[] = $k;
    }
}

print_r($returnData);

PHP Snippet 2:

<?php
$array['Alpha']="New York,Los Angeles,Washington";
$array['Beta']="New York,Los Angeles,Honolulu";
$array['Gamma']="New York,Los Angeles,Washington";
$search = "Washington";

$result = array_keys(array_filter($array, function($a) use ($search) {
    return strpos($a, $search) > -1;
}));

print_r($result);

PHP Snippet 3:

Array
(
    [0] => Alpha
    [1] => Gamma
)