note 30588 added to function.strcmp
| From: | ahmed at somantic dot net | Date: | Sun, 23 Mar 2003 06:52:22 +0000 |
| Subject: | note 30588 added to function.strcmp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-45666@lists.php.net to get a copy of this message | ||
For some reason the strcmp fails for this function if the $item_to_compare->ID =
"AB123" or some similar string. This happened even though $ID = "AB123":
<pre>
function item_exists($ID)
{
// returns 0 for error
global $item_list; // this is an array of class objects
if (is_array($item_list))
{
foreach ($item_list as $key => $item_to_compare)
{
if (!strcmp($item_to_compare->ID, $ID))
{
unset ($item_list);
return $key;
}
}
}
// Else fail
unset ($item_list);
return 0;
}
</pre>
So I was forced to do this:
<pre>
function item_exists($ID)
{
// returns 0 for error
global $item_list;
if (is_array($item_list))
{
for($i = 0; $i < count($item_list); $i++)
{
if (!strcmp($item_list[$i]->ID, $ID))
{
unset ($item_list);
return $i;
}
}
}
// Else fail
unset ($item_list);
return 0;
}
</pre>
--
http://www.php.net/manual/en/function.strcmp.php
http://master.php.net/manage/user-notes.php?action=edit+30588
http://master.php.net/manage/user-notes.php?action=delete+30588
http://master.php.net/manage/user-notes.php?action=reject+30588