note 115673 added to function.array-search
| From: | marvin dot petker at borntocreate dot de | Date: | Fri, 05 Sep 2014 16:08:58 +0000 |
| Subject: | note 115673 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200376@lists.php.net to get a copy of this message | ||
Be aware of using array_search() in conditional statements.
$foo = array("one", "two");
if( $key = array_search("one", $foo) ){
echo "Found";
}
else{
echo "Not found";
}
//Ouput: Not found
"Not found" will be outputted beacause the returned key is 0 and that will be interpreted
as false in conditional statements.
----
Server IP: 72.52.91.14
Probable Submitter: 2003:7a:2f3d:69da:591e:f491:6f15:6001
----
Manual Page -- http://php.net/manual/en/function.array-search.php
Edit -- https://master.php.net/note/edit/115673
Del: integrated -- https://master.php.net/note/delete/115673/integrated
Del: useless -- https://master.php.net/note/delete/115673/useless
Del: bad code -- https://master.php.net/note/delete/115673/bad+code
Del: spam -- https://master.php.net/note/delete/115673/spam
Del: non-english -- https://master.php.net/note/delete/115673/non-english
Del: in docs -- https://master.php.net/note/delete/115673/in+docs
Del: other reasons-- https://master.php.net/note/delete/115673
Reject -- https://master.php.net/note/reject/115673
Search -- https://master.php.net/manage/user-notes.php