Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Using a variable for an "if "condition

is this possible?



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

10+ Year Member

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"';



echo "$a is equal to yes";




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?


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

WebmasterWorld Senior Member 10+ Year Member

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



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

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

A blast from the past ...

Variable condition statements [webmasterworld.com]


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

10+ Year Member

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

Featured Threads

Hot Threads This Week

Hot Threads This Month