I have a simple in_array()
with an array as needle example below, however I expect that my example should echo;
match found in the array
Given both needles exist in the haystack. However this code does not produce an echo. I was hoping someone could help me understand why i'm not getting a match here.
<?php
$needle = array('fjord', 'troz');
$haystack = array('troz', 'zort', 'fran', 'fjord');
if (in_array($needle, $haystack))
{
echo "match found in the array";
}
?>
I have read http://php.net/manual/en/function.in-array.php but am unsure why i'm not getting a match.
To avoid loops you can use array_intersect()
:
if(count(array_intersect($needle, $haystack)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With