note 40432 deleted from function.array-search by nlopess
| From: | nlopess@php.net | Date: | Wed, 03 Mar 2004 17:30:40 +0000 |
| Subject: | note 40432 deleted from function.array-search by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-66181@lists.php.net to get a copy of this message | ||
Note Submitter: brandon@indiemp3.com
----
I have had many problems with evaluating array_search when the key is at position 0. After many
hours trying to figure it out, here is the solution. Maybe it can save some time for y'all.
<?php
$array = array ("one" , "two" ,"three");
$pos = array_search ("one", $array);
if ($pos === FALSE)
echo "Not In Array";
else
echo "In array at position: $pos";
?>
YOu must use the "===" operator that not only checks values, but also variable types .. ie
..
<?php
$value = (int) 0;
$bool = (bool) FALSE;
if ($value == $bool) ... would return TRUE
if ($value === $bool) ... would return FALSE
?>