Forum Moderators: coopster

Message Too Old, No Replies

what's wrong with this code?

         

jimmyyami

7:57 am on Oct 16, 2007 (gmt 0)

10+ Year Member



<?
$krida = rand(1,2);

if ($krida = "1"){

echo " I hate you! ";

} else {

echo " I love you! ";
}
?>

it just doesn't work correctly.

dreamcatcher

8:05 am on Oct 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if ($krida == "1"){

dc

jimmyyami

8:55 am on Oct 16, 2007 (gmt 0)

10+ Year Member



It work, thanks you very much!

leadegroot

12:43 pm on Oct 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



the 'old programmer' fix to this problem as a policy, is to always put the non changing part of the comparison first.
ie if you had put in

if (1 = $krida) {

then the parser would have thrown an error and you wouldn't have been wondering what the problem is.
Because its non-intuitive, its a hard habit to build, but its very worthwhile :)