homepage Welcome to WebmasterWorld Guest from 107.21.135.68
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Using a variable for an "if "condition
is this possible?
rover




msg:1280785
 10:03 pm on Feb 16, 2006 (gmt 0)

Is there any way to have a condition for an if statement be evaluated according to its contents and not whether the variable is defined or not? In other words:

$a = 'no';

$the_condition = '$a == "yes"';

if($the_condition)

{

echo "$a is equal to yes";

}

else

{

echo "$a is not equal to yes";

}

This will always evaluate as true and print yes because $the_condition variable is defined.

Is there any syntax so that I can have it actually evaluate the condition within the variable and whether that is true or not?

 

bedlam




msg:1280786
 10:32 pm on Feb 16, 2006 (gmt 0)

Sounds like a job for switch [php.net].

-b

coopster




msg:1280787
 10:50 pm on Feb 16, 2006 (gmt 0)

A blast from the past ...

Variable condition statements [webmasterworld.com]

rover




msg:1280788
 2:27 am on Feb 17, 2006 (gmt 0)

Thanks very much, those posts helped me solve it using the eval function.

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