note 116421 deleted from function.array-search by salathe

From: Date: Fri, 02 Jan 2015 11:34:41 +0000
Subject: note 116421 deleted from function.array-search by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-201338@lists.php.net to get a copy of this message
Note Submitter: fatcow at gmail dot com ---- The array_search method doesn't return true, as one might otherwise expect it to, on the 1st array node (key: 0). If you're just trying to detect the existence of a value in an array, then 'in_array' is the method you'll want to use, not this. <?php $array = array(1,2); // returns false if (array_search(1,$array)) { print "checked"; } // returns true if (in_array(1,$array)) { print "checked"; } ?>

« previous php.notes (#201338) next »