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 6051707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:50:52+00:00 2026-05-23T07:50:52+00:00

The following code: $result = (false or true); echo(With extra parentheses: .($result?true:false)); $result =

  • 0

The following code:

  $result = (false or true);
  echo("With extra parentheses: ".($result?"true":"false"));
  $result = false or true;
  echo("<br />With no parentheses: ".($result?"true":"false"));

generates the output:

With extra parentheses: true
With no parentheses: false

I do not understand why. Shouldn’t php evaluate $result = false or true; by first testing false and then, since it isn’t true, going on to evaluate true?

Any suggestions would be much appreciated.

  • 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-05-23T07:50:53+00:00Added an answer on May 23, 2026 at 7:50 am

    The or operator has a weaker precedence than the assignment operator. What really happens in the second case is ($result = false) or true, so the part or true really has no effect.

    The assignment operator yields the assigned value as its result, false in this case. Think of the assignment operator as an ordinary binary operator that yields a result (like +, < and or), with the only difference that it has a side effect.

    If you want to avoid the parentheses, you can swap or for ||, which has a stronger precedence.

    Always be careful when using the English versions of the logical operators, because their precedence is different.

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

Sidebar

Related Questions

I'm really stuck on why the following code block 1 result in output 1
Will the following code result in a deadlock using C# on .NET? class MyClass
I have the following code in action script 3: async.addResponder(new Responder(result, defaultFaultHandler)); result is
I have the following code : std::string Utils::get() { std::string result; result.append(1, 'x'); result.append(1,
Inside my template function I have the following code: TypeName myFunction() { TypeName result;
I have the following code: public static T ParameterFetchValue<T>(string parameterKey) { Parameter result =
The following snippet of C# code: int i = 1; string result = String.Format({0},{1},{2},
currently i obtain the below result from the following C# line of code when
I have the following code which uses an array to write the result to
The following code draws a labyrinth or maze in OpenGL, the result is a

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.