USE CASE :
$a = [1, 2, [3, 4, 5], [6, [7, 8], 8, 10]];
isNumberPresentInArray($a, 10) // returns true;
isNumberPresentInArray($a, 2) // returns true;
isNumberPresentInArray($a, 14) // returns false;
I would like to check if there element exist in array.The following is my version of code. but its not working perfectly for inner arrays. Please help me.
$a = [1, 2, [3, 4, 5], [6, [7, 8], 8, 10]];
function isNumberPresentInArray($a, $b) {
foreach($a as $v)
{
if (is_array($v)) {
return isNumberPresentInArray($v, $b);
} else {
if ($v == $b) {
return true;
}
}
}
}
echo isNumberPresentInArray($a, 1);