Welcome to WebmasterWorld Guest from 54.196.217.43

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

if $var1=1 then $var2=4

     
12:55 am on Apr 20, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Nov 16, 2008
posts:136
votes: 0


Hi everyone its me again!

I was wondering how could I do that?

$var1=1;
$var2=2;

if ($var1=1) then $var2=4

it would not =2 anymore? Anyway to do this? I may be not clear but I dont know how to explain it differently..

Thanks
8:40 am on Apr 20, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Dec 7, 2008
posts: 77
votes: 0


I hope it will work

$var1=1;
$var2=2;

$var2 = ($var1 == 1 ) ? 4 : $var2;
11:42 am on Apr 20, 2011 (gmt 0)

Junior Member

joined:Feb 25, 2011
posts: 91
votes: 0


$var = 1, assigns 1 to $var and returns it (1). Therefore

if ($var = 1)

is the same as:

$var = 1;
if (1)
12:05 pm on Apr 20, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 8, 2003
posts:1141
votes: 0


Keep in mind that:

if ($var1=1)

is not the same as

if ($var1==1)

I am not quite sure what you are doing but if I understand it correctly you want:

if ($var1 == 1) $var2 = 4;
1:34 pm on Apr 20, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Nov 16, 2008
posts:136
votes: 0


ok so i'll try to be more specific!
i have declared two variables
$var1=rand(0,1);
$var2=rand(0,1);

And what i want to do is

if $var1=0 then $var2 can = 0 or 1
But if $var1=1 $var2 can just = 0

i know it's not really what i explained first but thats what i need to know how to do!

Thanks! ;)
1:37 pm on Apr 20, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 8, 2003
posts:1141
votes: 0


$var1=rand(0,1);

if ($var1==0) $var2=rand(0,1);
else $var2=0;

or

$var1=rand(0,1);
$var2=rand(0,1);
if ($var1==1) $var2=0;
1:45 pm on Apr 20, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Nov 16, 2008
posts:136
votes: 0


damn! that was fast! :O thanks a lot :D