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

  • SEARCH
  • Home
  • 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 943935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:30:48+00:00 2026-05-15T22:30:48+00:00

if ($var == ($var1 || $var2)) { … } I am considering using this,

  • 0
if ($var == ($var1 || $var2))
{
    ...
}

I am considering using this, but am ont sure if it is valid, and there doesn’t seem to be somewhere to check.
It seems logically consistent to me but am not sure, and I don’t have something to test it on close by.
If it is valid, what other mainstream languages support this sort of construct.

EDIT: The comparison is valid, but not in the way I was thinking.
What I was trying to do was actually the in_array() function, which I just discovered.

  • 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-15T22:30:48+00:00Added an answer on May 15, 2026 at 10:30 pm

    Your code is syntactical valid but semantical probably not what you wanted.

    Because $var1 || $var2 is a boolean expression and always yields true or false. And then $var is compared to the result of that boolean expression. So $var is always compared to either true or false and not to $var1 or $var2 (that’s what you’re have probably expected). So it’s not a shorthand to ($var == $var1) || ($var == $var2).

    Now as you already noted yourself, in_array is a solution to this problem if you don’t want to write expressions like ($var == $var1) || ($var == $var2), especially when you have an arbitrary number of values you want to compare to:

    in_array($var, array($var1, $var2))
    

    Which is equivalent to:

    ($var == $var1) || ($var == $var2)
    

    If you need a strict comparison (using === rather than ==), set the third parameter to true:

    in_array($var, array($var1, $var2), true)
    

    Which is now equivalent to:

    ($var === $var1) || ($var === $var2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 510k
  • Answers 510k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you are calling the function directly when the swf… May 16, 2026 at 5:05 pm
  • Editorial Team
    Editorial Team added an answer You should put such information into app.config / web.config file… May 16, 2026 at 5:05 pm
  • Editorial Team
    Editorial Team added an answer The problem is that the second test div is inside… May 16, 2026 at 5:05 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

var var1 = 1, var2 = 1, var3 = 1; This is equivalent to
I have a class like this $.fn.dimeBar = function(custom) { var var1 = 'test1';
I need to extract in actionscript the variables from a string like /var1/var2/var3/... Each
Not sure if this is possible in Dojo or JS for a function to
I have a string with nested groups like this ('blabla' is some text within
In graphviz I would like to have an edge that doesn't cross the node.
var ajaxRequestqqq; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox,
var selValues = {}; selValues['234'] = $('#asd').val(); selValues['343'] = function () { var el
var array1 = {}; array1['one'] = new Array(); array1['one']['data'] = 'some text'; array1['one']['two'] =
var div1 = $(<div>); var div2 = $(<div>); var div3 = $(<div>); $('#container').html('').append(div1).append(div2).append(div3); What

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.