note 93780 added to function.array-search

From: Date: Tue, 29 Sep 2009 04:29:54 +0000
Subject: note 93780 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-161132@lists.php.net to get a copy of this message
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"; ?> ---- Server IP: 117.104.162.229 Probable Submitter: 134.7.248.130 ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- https://master.php.net/note/edit/93780 Del: integrated -- https://master.php.net/note/delete/93780/integrated Del: useless -- https://master.php.net/note/delete/93780/useless Del: bad code -- https://master.php.net/note/delete/93780/bad+code Del: spam -- https://master.php.net/note/delete/93780/spam Del: non-english -- https://master.php.net/note/delete/93780/non-english Del: in docs -- https://master.php.net/note/delete/93780/in+docs Del: other reasons-- https://master.php.net/note/delete/93780 Reject -- https://master.php.net/note/reject/93780 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161132) next »