String comparison to 0 returning true
Posted: Tue Jan 16, 2007 11:14 am
Can someone help me understand this? I have the following code:
The value of $userdata['use_plcy_dttm'] for the account I am testing is: Dec 28 2006 1:19PM (after the trim). A var dump of the array value and the assigned var value:
Returns:
Return:
Code: Select all
<?php
// Users last accept date
$user_last_accept_date = (trim($userdata['use_plcy_dttm']));
?>Code: Select all
<?php
echo '<pre>'; var_dump($userdata['use_plcy_dttm']); echo '</pre>';
echo '<pre>'; var_dump($user_last_accept_date); echo '</pre>';
?>So why, when I run this conditional, do I get a boolean true on my comparison?string(19) "Dec 28 2006 1:19PM"
string(19) "Dec 28 2006 1:19PM"
Code: Select all
<?php
if (0 == $user_last_accept_date)
{
//$user_last_accept_date = 'Jan 1, 1970 1:00AM';
echo $user_last_accept_date . ' shows as 0 (' . var_dump(($user_last_accept_date == 0)) . ')...<br />';
}
?>What the heck am I doing wrong? I know it is simple, and I am sure I am doing something utterly stupid because logically this makes no sense to me. Here is the code in full, as it written before seeing this issue:bool(true) Dec 28 2006 1:19PM shows as 0 ()...
Code: Select all
<?php
/*
Everah |
For testing, assume value of $userdata['use_plcy_dttm] = 'Dec 28 2006 1:19PM'
*/
// Users last accept date
$user_last_accept_date = (trim($userdata['use_plcy_dttm']));
if (0 == $user_last_accept_date)
{
//$user_last_accept_date = 'Jan 1, 1970 1:00AM';
}
?>