note 93852 deleted from control-structures.if by cmb
| From: | cmb@php.net | Date: | Fri, 02 Oct 2020 12:59:49 +0000 |
| Subject: | note 93852 deleted from control-structures.if by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215522@lists.php.net to get a copy of this message | ||
Note Submitter: austinderrick2 at gmail dot com
----
As an added note to the guy below, in such a case, use the !== operator like this.
$nkey = array_search($needle, $haystack);
if ($nkey !== false) { ...
The !== and the === compare the "types". So, with this type of comparision, 0 is not the
same as the FALSE returned by the array_search array when it can not find a match. :)
Quoted Text:
===================================
Be careful with stuff like
if ($nkey = array_search($needle, $haystack)) { ...
if the returned key is actually the key 0, then the if won't be executed
===================================