By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

PHP If And

How to include PHP If And cases in your If Statements. Just a quick reminder.

Edited: 2012-04-11 22:15

php if and cases can be useful when you only want certain code to be run, when two or more cases match.

The Syntax for And cases are similar to Or cases, you only have to change the operator used. The operator for If and's is two ampersands "&&".

PHP If And Example

The below shows how to make certain code run, only when multiple cases have returned true.

If you want the code to be run if either of the cases return true, than read: PHP If Or

if (($a == "a") && ($b == "b")) {
 // The code placed here will only be run if both cases returned true

If it doesn't work

Sometimes people cant get their If Statements to work, simply because they use the wrong operators. Below is a list of Operators, and explanation about what each of them mean.

< Less then
> Greater then
= Equal to
== Exactly Equal to
=== Identical
!= Not Equal to
<= Less then or Equal to
>= Greater then or Equal to

See also

  1. PHP If Then Else and ElseIf Statements