Multiple conditions in an If statement

To combine conditions, use the set of logical operators. The common ones are

&& AND
|| OR

Combine conditions inside the brackets of an 'if' statement. Examples:

if ( ($day > 28) && ($month = 2) ) {
    echo "There are only 28 days in February!";
}


if ( ($name == "John") || ($name == "James") ) {
    echo "Your name is John or James!";
}




Back to loops and decisions article

Using Nested If statements

If you want to test for many different conditions, you can nest the If statements

if ($month = 12) {
    echo "Welcome to December";
    if ($day = 24) {
        echo "It's Christmas Eve!";
    }
    if ($day = 25) {
        echo "It's Christmas Day!";
    }
}



Back to loops and decisions article

Previous

The previous article tells you how to use loops and how to make decisions in PHP.

Next

The next screen gives you a tutorial on how to use the date function in PHP.
This tutorial tells you how to retrieve dates and times, including the current date and time.

External Links

Summary

  • Create an array using the key values and a value for each element
  • Add to the end of a numeric array using []
  • Retrieve an element in an array using its key
  • Use count to find out how many elements are in an array