PDA

View Full Version : rand and if problem


gsnedders
03-13-2004, 07:29 PM
<html>
<head>
<title>WHY?</title>
</head>
<body>
<?PHP

$strRan = rand(1, 15);

If ($strRan = 15) {echo ('The number is 15');} else {echo ('The number is not 15');}

?>
</body>
</html>For me it always says The number is 15.

mordred
03-13-2004, 07:48 PM
That's correct. You are accidentally reassigning the value of $strRan in your if-statement, because you lost one equality sign. You'd rather need:


If ($strRan == 15) {echo ('The number is 15');} else {echo ('The number is not 15');}

gsnedders
03-13-2004, 08:23 PM
I don't understand why I need 2, so can you tell me, but thanks for fixing the problem (had to load it 20 times to make it say that :D).

Nightfire
03-13-2004, 08:26 PM
Two means equal to.

http://www.w3schools.com/php/php_operators.asp

gsnedders
03-13-2004, 08:40 PM
Originally posted by Nightfire
Two means equal to.

http://www.w3schools.com/php/php_operators.asp

Thanks.