note 115673 deleted from function.array-search by cmb
| From: | cmb@php.net | Date: | Sun, 05 Jan 2020 08:20:57 +0000 |
| Subject: | note 115673 deleted from function.array-search by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213750@lists.php.net to get a copy of this message | ||
Note Submitter: marvin dot petker at borntocreate dot de
----
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.