note 35589 added to function.max

From: Date: Sun, 07 Sep 2003 11:05:18 +0000
Subject: note 35589 added to function.max
Groups: php.notes 
Request: Send a blank email to php-notes+get-55562@lists.php.net to get a copy of this message
On jesusjr at mindless dot com's note The problem he mentioned is very important but his guess is wrong for sure. Of course, PHP doesn't evaluate any expressions inside quotation marks. "n/a" is treated as "n/a", not as 0/0. You can place "foo" instead of "n/a" and get same result. My guess of such behavior is: PHP compares 4 and "5" and treats "5" as max. Then compares "5" which is STRING "5" to string "n/a" and the last one is going to be max. In other words, if there is a string element whose integer value is more than that of other integer values and also string element which is really string such as "foo", "bar" etc. the last one always going to be max. I am not sure it is a bug, so I'm leaving this comment here. The only solution i see here is manually convert integers which has string type to integers before comparsion. This code may help: if ($var==strval(intval($var))) $var=intval($var); Probably, float numbers need same conversion. But this conversion won't help in case of "55pigs". So, the best solution is always compare only variavbles of same type. ---- Manual Page -- http://www.php.net/manual/en/function.max.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35589 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35589&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35589&report=yes

« previous php.notes (#55562) next »