Sam Khan
Sam Khan

Reputation: 2477

How to add a second condition to this equal statement?

I am using this snippet below, how can i add a second equal statement with an "and" so something like ($onevariable === $othervariable) and ($2variable ===$2othervariable)

  if ( $onevariable === $othervariable ) {
  require("file.php");
  }

Upvotes: 1

Views: 62

Answers (5)

stivlo
stivlo

Reputation: 85476

Just use the logical and operator &&. You can also use and if you prefer, but && is more in use. The only difference between the two is operator precedence.

if ($onevariable === $othervariable && $2variable === $2othervariable) {
    require("file.php");
}

Upvotes: 1

hakre
hakre

Reputation: 197648

This is fairly straight-forward, it's just how you already wrote in your question:

if ( ($onevariable === $othervariable) and ($2variable === $2othervariable) ) {
    require("file.php");
}

See as well Logical Operators (PHP).

Note: $2variable is not a valid variable name, as well isn't $2othervariable because they start with a number. But I think you get the idea from the example code.

Upvotes: 1

ScoRpion
ScoRpion

Reputation: 11474

You can Directly use the && operator like this

if ( $onevariable === $othervariable && $2variable ===$2othervariable )
{
  require("file.php");
}

further You can visit here

Upvotes: 2

Marcus
Marcus

Reputation: 12586

You do this with &&

if ( $onevariable === $othervariable && $2variable === $2othervariable) {

You can read more about logical operators here.

Upvotes: 2

Clive
Clive

Reputation: 36957

You can use a simple && operator:

if ( $onevariable === $othervariable && $2variable === $2othervariable ) {
  require("file.php");
}

Upvotes: 1

Related Questions