I modified a function that searches through an array to return the parent item if a value is found within the array. It works fine for returning the first item found but I want it to return all the items found. I presume it’s because i’m returning the array right away but i’m not sure how to change it to make it “go back” and return multiple finds.
Function:
function in_array_r($needle, $haystack) {
foreach ($haystack as $item) {
if ($item === $needle || (is_array($item) && in_array_r($needle, $item))) {
return $item;
}
}
return false;
}
Instead of returning right away, just append $item in an array. Replace
return falsewithreturn $your_array(the one containing your items). $your_array will therefore contain every item matching your condition.