note 93780 deleted from function.array-search by levim

From: Date: Mon, 24 Feb 2014 22:44:23 +0000
Subject: note 93780 deleted from function.array-search by levim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-198697@lists.php.net to get a copy of this message
Note Submitter: pi3ch at gmx dot com ---- The return value for array_search is confusing if the return key is zero. it is better to double check it with in_array() function. Example: <?php $SampleArray = ('a', 'b', 'c'); $Key = array_search('a', $SampleArray); $Zero = in_array('a', $SampleArray); if($Key == NULL && !$Zero) echo "Key doesnt exists"; else echo "Key exists"; ?>

« previous php.notes (#198697) next »