note 79146 deleted from language.types.string by danbrown

From: Date: Tue, 17 May 2011 14:17:49 +0000
Subject: note 79146 deleted from language.types.string by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179812@lists.php.net to get a copy of this message
Note Submitter: qriz at example dot com ---- <?php $a = '2007-11-05 15:17:49'; $b = '2007-11-05 15:17:48'; $bool = $a > $b; var_dump($bool); //bool(true) ?> works correctly since there is a comparing between strings. The comparisson is done on the last number/letter (since thats the only thing that is difference in the string) and that is in this case: the 9 and 8. 8 > 9 = true if you want to compare the string as pure numbers then you must type cast it to numbers or type juggle it: <?php $a = '2007-11-05 15:17:49'; $b = '2007-11-05 15:17:48'; $bool1 = ($a + 0) > ($b + 0); // 2007 > 2007 $bool2 = (int) $a > (int) $b; // 2007 > 2007 $bool3 = intval($a) > intval($b); // 2007 > 2007 var_dump($bool1,$bool2,$bool3); //bool(false) ?>

« previous php.notes (#179812) next »