note 49320 added to language.control-structures

From: Date: Mon, 24 Jan 2005 05:03:30 +0000
Subject: note 49320 added to language.control-structures
Groups: php.notes 
Request: Send a blank email to php-notes+get-83854@lists.php.net to get a copy of this message
Hi, Php Developers. I got a little problem when I use simple expresions to parse, and I need a numeric value, in which zero is a valid number. Example $myMinVal = 1; $myMaxVal = 10; if( $myMinVal ) echo "Your Min Value is: ".$myMinVal."<br>"; if( $myMaxVal ) echo "Your Max Value is: ".$myMaxVal."<br>"; In this case the result must be: Your Min Value is: 1 Your Max Value is: 10 It was good, but if $myMinVal=0 or $myMaxVal=0, the script won`t print the Min or Max string, If someone (just like me) has a similar problem is recommended to use the function is_numeric(), that parse only numeric values, including the zero value. If there is another shorter way, please tell me. Example. (Keep on mind that in this case 0 is not false) Wrong Script. $myMinVal = 0; $myMaxVal = 10; if( $myMinVal ) echo "Your Min Value is: ".$myMinVal."<br>"; if( $myMaxVal ) echo "Your Max Value is: ".$myMaxVal."<br>"; In this case the result must be: Your Max Value is: 10 <b>Right Script</b> $myMinVal = 0; $myMaxVal = 'NaN'; if( is_numeric($myMinVal) ) echo "Your Min Value is: ".$myMinVal."<br>"; if( is_numeric($myMaxVal) ) echo "Your Max Value is: ".$myMaxVal."<br>"; A good Result Your Min Value is: 0 Carlos J Acuña ---- Manual Page -- http://www.php.net/manual/en/language.control-structures.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49320 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49320&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49320&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49320&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49320&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49320&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49320&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#83854) next »