Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I was wondering how can I assign a conditional assignment to a php variable and use it inside other conditional, like this:
$cndtnal='&& $x==4' if($y==5 $cndtnal){ print 'Hello World'; }
Thanks.
if (eval('$y==5'.$cndtnal))
$x=4
true
You should try avoiding the use of eval as much as possible, but if you want to use it, then you could do:
$cndtnal='&& $x=4'; if($y==5 .eval("return '$cndtnal';") ){ echo 'Hello World'; } else { echo "this"; }
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
if (eval('$y==5'.$cndtnal)). But it is evil. I urge you find another way to do it.$x=4will always evaluate totrueand as such there's no reason to include it in your equality statement, right?