note 49320 rejected from language.control-structures by nlopess
| From: | nlopess@php.net | Date: | Mon, 24 Jan 2005 20:14:22 +0000 |
| Subject: | note 49320 rejected from language.control-structures by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-83889@lists.php.net to get a copy of this message | ||
Note Submitter: cjacunad at unal dot edu dot co
----
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