search string in comma separated array php -
i need return array contains search string in range . want search string pakistan1 , not take above that should ignore array key 0 second string bangladesh4 should ignore other keys below 4 final return array should
array( [2]=> [3]=> [4]=> )
there 2 strings needs searched. how can go ?
first : pakistan2
second : bangladesh4
$input_arr= array( 0=>array(india0,srilanka1,pakistan0,banglades0), 1=>array(india1,srilanka1,pakistan1,bangladesh1), 2=>array(india2,srilanka2,pakistan2,bangladesh2), 3=>array(india3,srilanka3,pakistan3,bangladesh3), 4=>array(india 4,srilanka4,pakistan4,bangladesh4), 5=>array(india 5,srilanka5,pakistan5,bangladesh5), );
i want return resulting array :
$result_arr= array( 2=>array(india2,srilanka2,pakistan2,bangladesh2), 3=>array(india3,srilanka3,pakistan3,bangladesh3), 4=>array(india 4,srilanka4,pakistan4,bangladesh4) )
edited
$first_str = "pakistan2"; $second_str = "bangladesh4"; $arr_output = array(); foreach($input_arr $key=>$temp_arr) { if(in_array($first_str, $temp_arr) || in_array($second_str, $temp_arr) ) { $arr_output[$key]=$temp_arr; } }
not able array 3
try this
$input_arr= array( 0=>array("india0","srilanka1","pakistan0","banglades0"), 1=>array("india1","srilanka1","pakistan1","bangladesh1"), 2=>array("india2","srilanka2","pakistan2","bangladesh2"), 3=>array("india3","srilanka3","pakistan3","bangladesh3"), 4=>array("india 4","srilanka4","pakistan4","bangladesh4"), 5=>array("india 5","srilanka5","pakistan5","bangladesh5"), ); $first_str = "pakistan2"; $second_str = "bangladesh4"; $arr_output = array(); foreach($input_arr $key=>$temp_arr) { if(in_array($first_str, $temp_arr) || in_array($second_str, $temp_arr) ) { $arr_output[$key]=$temp_arr; } } print_r($arr_output);
Comments
Post a Comment