note 94885 deleted from function.in-array by cmb
| From: | cmb@php.net | Date: | Mon, 21 Jan 2019 14:23:09 +0000 |
| Subject: | note 94885 deleted from function.in-array by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210090@lists.php.net to get a copy of this message | ||
Note Submitter: natan dot volkovich at gmail dot com
----
If you're trying to find out whether or not at least a single value of an array matches a value
in your haystack then use "array_intersect" instead of "in_array".
<?php
$needle = array(1,2);
$haystack = array(0,1,2);
echo "in_array: ".(int)in_array($needle, $haystack); // returns 0
echo "array_intersect: ".(int)array_intersect((array)$needle, $haystack); // returns 1
?>