Welcome to WebmasterWorld Guest from 54.224.13.210

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)

Full Member

10+ Year Member

joined:Jan 5, 2004
posts:202
votes: 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?

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 30, 2003
posts:728
votes: 0


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

-b

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

Administrator

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

joined:July 31, 2003
posts:12548
votes: 2


A blast from the past ...

Variable condition statements [webmasterworld.com]

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

Full Member

10+ Year Member

joined:Jan 5, 2004
posts:202
votes: 0


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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members