note 40432 added to function.array-search
| From: | brandon at indiemp3 dot com | Date: | Wed, 03 Mar 2004 17:06:43 +0000 |
| Subject: | note 40432 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-66176@lists.php.net to get a copy of this message | ||
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
?>
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+40432
Delete -- http://master.php.net/manage/user-notes.php?action=delete+40432&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+40432&report=yes
Search -- http://master.php.net/manage/user-notes.php