Welcome to WebmasterWorld Guest from 54.162.139.217

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

# if \$var1=1 then \$var2=4

#### skoff

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

#### Junior Member

joined:Nov 16, 2008
posts:136

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

#### Mahabub

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

#### Junior Member

joined:Dec 7, 2008
posts: 77

I hope it will work

\$var1=1;
\$var2=2;

\$var2 = (\$var1 == 1 ) ? 4 : \$var2;

#### mbabuskov

11:42 am on Apr 20, 2011 (gmt 0)

#### Junior Member

joined:Feb 25, 2011
posts: 91

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

if (\$var = 1)

is the same as:

\$var = 1;
if (1)

#### jecasc

12:05 pm on Apr 20, 2011 (gmt 0)

#### Senior Member

joined:May 8, 2003
posts:1141

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;

#### skoff

1:34 pm on Apr 20, 2011 (gmt 0)

#### Junior Member

joined:Nov 16, 2008
posts:136

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! ;)

#### jecasc

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

#### Senior Member

joined:May 8, 2003
posts:1141

\$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;

#### skoff

1:45 pm on Apr 20, 2011 (gmt 0)

#### Junior Member

joined:Nov 16, 2008
posts:136

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