RE: [PHP] whats wrong with this?
| From: | Hankley, Chip | Date: | Wed, 28 Aug 2002 16:15:07 +0000 |
| Subject: | RE: [PHP] whats wrong with this? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-114380@lists.php.net to get a copy of this message | ||
you need to use "==" instead of "="
"==" is used when comparing values (i.e. is this "==" to that)
"=" is used to set something's value (i.e. this "=" that)
-chip
-----Original Message-----
From: Chris Barnes [mailto:runtimeerror@bigpond.com]
Sent: Wednesday, August 28, 2002 11:12 AM
To: Php-General (E-mail)
Subject: [PHP] whats wrong with this?
I just cant seem to work out why this doesn't work. My PHP book doesn't
explain "if" statements very well so i have no idea if i am breaking a rule.
$system_day = date("j");
for($day = 1; $day < 32; $day++){
if($day = $system_day){
echo "match!";
}
else{
echo "no match";
}
}
the problem i am experiencing is that it seems the "if" statement is setting
the $day value to equal $system_day instead of comparing their values....
if i add
echo "Day: " . $day . " System_day: " . $system_day;
before and after the if statement then the first result is something like
Day: 1 System_day: 29
after the "if" statement has executed the result is
Day: 29 System_day: 29
so you see, instead of "if" comparing $day to $system_day it is making $day
equal to $system_day.
any ideas why and how to fix this?
help is most appreciated :)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php