note 53626 added to function.array-search
| From: | JamesGolick at osu1 dot php dot net | Date: | Tue, 07 Jun 2005 17:14:26 +0000 |
| Subject: | note 53626 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90076@lists.php.net to get a copy of this message | ||
<?php
$array = array( 0 => "value" );
if ( array_search( "value", $array ) )
{
echo "found";
}
else
{
echo "not found";
}
?>
The above will echo not found, because php accepts 0 to be the same as false.
The solution is as follows
<?php
function remove0(&$array)
{
$array[] = $array[0];
unset($array[0]);
}
?>
see my blog
http://phpmethods.blogspot.com
James
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+53626
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53626&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53626&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53626&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53626&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53626&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+53626&report=yes
Search -- http://master.php.net/manage/user-notes.php