Welcome to WebmasterWorld Guest from 23.22.46.195

Forum Moderators: coopster & jatar k

if $var1=1 then $var2=4

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

5+ Year Member



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)

5+ Year Member



I hope it will work

$var1=1;
$var2=2;

$var2 = ($var1 == 1 ) ? 4 : $var2;
11:42 am on Apr 20, 2011 (gmt 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)

WebmasterWorld Senior Member 10+ Year Member



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)

5+ Year Member



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)

WebmasterWorld Senior Member 10+ Year Member



$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)

5+ Year Member



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

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month