note 94885 modified in function.in-array by danbrown

From: Date: Tue, 01 Dec 2009 16:12:55 +0000
Subject: note 94885 modified in function.in-array by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-163453@lists.php.net to get a copy of this message
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 ?> --was-- 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". $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 http://php.net/manual/en/function.in-array.php

« previous php.notes (#163453) next »