I know a lot of questions that have already been asked about this problem, but I could not find the right answer for my specific problem.
I have a search bar - "1 | 1"
I have an array containing the following values: "a" => "1 | 1", "b" => "2 | 1,1 | 1", "c" => "3 | 2,2 | 1"
All I want to do is just find if the search string exists in the array, it should return the key of the array. If several elements of the array have a search string, they should return all of them.
In this example, I expect to get "a" and "b", but when I use it strpos(), it gives me only "a".
How can I solve this problem?
Change **
This is my code.
function array_search_i($str, $array)
{
$returnArray = array();
foreach ($array as $key => $value) {
if (strpos($str, $value) !== false) {
array_push($returnArray, $key);
}
}
return $returnArray;
}