Suppose you have some strings, how should I transform them in order to be able to use logical operations on them in PHP? Is it even possible?
Example: I want
"x=1"&&"x=0"
to return false.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Introduction
I noticed you have both Logical Operator
&&and Assignment Operator in a string=and you want to evaluate the assignment has a logical operator in a string. Seriously i don’t know how you got here but this isvery wrongbut for education purpose tag alongBreakdown
The above expression would always be
falsebecauseXcan not beequalto0and1at the same timeTo be able to have such evaluation in
PHPyou need to write your own function eglogicalStringwhere you can evaluate the expression with something likelogicalString("x=1")orlogicalString("x=0")Assumption
Example 1 &&
Output 1
Example 2 – ||
Output 2
Function Used ( Not to be used in production See Why )
SEE ONLINE DEMO on PHP 4.3.0 – 5.5.0alpha3