Re: testing for negative numbers

From: Date: Thu, 06 Feb 2003 08:57:38 +0000
Subject: Re: testing for negative numbers
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-134566@lists.php.net to get a copy of this message
Please provide a complete test script. Are you perhaps not realizing that array indices along with all variables in PHP are case sensitive? $row["ID"] and $row["id"] are not the same thing. The trivial test of your example: $myArray["id"] = -2; if ($myArray["id"] < 0) echo "Negative"; else echo "Positive"; Prints "Negative" as expected. -Rasmus On Thu, 6 Feb 2003, Robert Samuel White wrote: > I realize this should be about the simplest thing in the world to do, > but for this reason or that it's not working... > > I'm using PHP version 4.2.3 > > Whether I have a negative number in an array, for example: > > $myArray["ID"] = -2 > > Or the number comes from the database, for example: > > $row["id"] = -2 > > I cannot get this simple operation to work: > > if ($row["id"] < 0) > > Instead, positive or negative, it seems to think this expression is > always true: > > if ($row["id"] > 0) > > It's like it takes the absolute value of the number (whether the number > is 2 or -2, it thinks it is 2) > > I've tried many things, including type casting using (int) in front of > the expression. > > Nothing has worked. > > Any ideas why in the world this is happening? Thanks. > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#134566) next »