Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9119641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:26:41+00:00 2026-06-17T05:26:41+00:00

Suppose you have some strings, how should I transform them in order to be

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:26:43+00:00Added an answer on June 17, 2026 at 5:26 am

    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 is very wrong but for education purpose tag along

    Breakdown

    "x=1"  &&  "x=0" = False 
      ^    ^     ^
      |    |     | 
           |     |
    X == 1 |     |
           |     |
          AND    |
                 |
               X == 0
    

    The above expression would always be false because X can not be equal to 0 and 1 at the same time

    To be able to have such evaluation in PHP you need to write your own function eg logicalString where you can evaluate the expression with something like logicalString("x=1") or logicalString("x=0")

    Assumption

    $x = 1; // Imagine value of X 
    

    Example 1 &&

    // Start Evaluation with &&
    if (logicalString("x=1") && logicalString("x=0")) {
        echo "&& - True\n";
    } else {
        echo "&& - False\n";
    }
    

    Output 1

    && - False 
    

    Example 2 – ||

    // Start Evaluation with ||
    if (logicalString("x=1") || logicalString("x=0")) {
        echo "|| - True\n";
    } else {
        echo "|| - False\n";
    }
    

    Output 2

    || - True
    

    Function Used ( Not to be used in production See Why )

    function logicalString($str) {
        parse_str($str, $v);
        foreach ( $v as $k => $var ) {
            if (! isset($GLOBALS[$k]) || $GLOBALS[$k] != $var)
                return false;
        }
        return true;
    }
    

    SEE ONLINE DEMO on PHP 4.3.0 – 5.5.0alpha3

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have some strings: string[] strings = { zero, one, two, three, four,
suppose I have this string: some striinnngggg <a href=something/some_number>linkk</a> soooo <a href=someotherthing/not_number>asdfsadf</a> I want
Suppose I have the following code: foreach(string str in someObj.GetMyStrings()) { // do some
Suppose you have some complex JSON like: {A : valA, B : { C
Suppose I have some class which has a property actor_ of type Actor .
Suppose I have some pointer, which I want to reinterpret as static dimension array
Propose to consider the following problem. Suppose we have some composite object. Are there
Lets suppose that I have some pages some.web/articles/details/5 some.web/users/info/bob some.web/foo/bar/7 that can call a
I have some not understanding actions from gnu clisp Suppose, I have some code
I have some questions about using MySQLi queries, and related memory management. Suppose I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.