homepage Welcome to WebmasterWorld Guest from 184.73.104.82
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
if $var1=1 then $var2=4
skoff

5+ Year Member



 
Msg#: 4300841 posted 12:55 am on Apr 20, 2011 (gmt 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

 

Mahabub

5+ Year Member



 
Msg#: 4300841 posted 8:40 am on Apr 20, 2011 (gmt 0)

I hope it will work

$var1=1;
$var2=2;

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

mbabuskov



 
Msg#: 4300841 posted 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)

jecasc

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4300841 posted 12:05 pm on Apr 20, 2011 (gmt 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;

skoff

5+ Year Member



 
Msg#: 4300841 posted 1:34 pm on Apr 20, 2011 (gmt 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! ;)

jecasc

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4300841 posted 1:37 pm on Apr 20, 2011 (gmt 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;

skoff

5+ Year Member



 
Msg#: 4300841 posted 1:45 pm on Apr 20, 2011 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved