I am trying to compare one array of values to another array of values. If they intersect, then I would proceed with the rest of my function. However, I can't seem to get array_intersect() to work properly.
Without getting to far into the code, I'll show you the output from debugging my PHP:
intersection: Array ( )
needle: Array ( [0] => 37211 [1] => 37212 [2] => 37213 [3] => 37214 )
haystack (cpt_codes): Array ( [0] => 70450 [1] => 38221 [2] => 37212 )
intersection: Array ( )
needle: Array ( [0] => 38221 [1] => G0364 )
haystack (cpt_codes): Array ( [0] => 70450 [1] => G0364 [2] => 37212 )
intersection: Array ( [0] => 38221 )
needle: Array ( [0] => 38221 [1] => G0364 )
haystack (cpt_codes): Array ( [0] => 70450 [1] => 38221 [2] => 37212 )
In the first example, you will notice that the value "37212" exists in both the needle and haystack, yet the intersection of these two arrays yields no results.
In the second example, you will notice that the value "G0364" exists in both the needle and haystack, yet the intersection of these two arrays yields no results.
In the third example, you will notice that "38221" is in both the needle and haystack, and the function displays the result properly.
Any thoughts? I don't care for the key value, I just need to know if there are ANY intersection values between the two arrays.
Thanks, IP
For completeness, I generated the above output from the following code.
echo "intersection: "; print_r(array_intersect(explode(",",$data[$i][7]), $cpt_codes_test)); echo "<br>";
echo "needle: "; print_r(explode(",",$data[$i][7])); echo "<br>";
echo "haystack (cpt_codes): "; print_r($cpt_codes_test); echo "<br><br>";