Key Concepts

Review core concepts you need to learn to master this subject

PHP else statement

$condition = FALSE; if ($condition) { // This code block will not execute } else { // This code block will execute }

A PHP else statement can follow an if block. If the condition of the if does not evaluate to TRUE, the code block following else will be executed.

Booleans and Comparison Operators
Lesson 1 of 1
  1. 1
    Have you ever noticed that hyperlinks change color after you click them? If the link has been clicked, then the web browser renders it in purple, rather than blue. The programming concept that …
  2. 2
    We’re going to learn about a specific type of conditional called an if statement. An if statement follows this basic structure: if (/some condition/) { // Do something… } The parentheses ho…
  3. 3
    The condition, or expression, in an if statement can hold a boolean value—like TRUE or FALSE, a variable assigned to one of those values, or an expression that evaluates to TRUE or FALSE. Just …
  4. 4
    In this exercise we’re going to learn a few more comparison operators and see how we can use them to compare more than just number values. The identical operator (===) will return TRUE if the lef…
  5. 5
    So far, we’ve been writing conditionals that can only handle one condition. If that condition is met, we do one thing, otherwise we do something else. This only allows us one or two courses…
  6. 6
    We often want to compare a value, expression, or variable against many different possible values and run different code depending on which it matches. We can use a series of if/elseif statements wh…
  7. 7
    In the previous exercise, we taught you to use the keyword break after the block for each case. Without the keyword break, not only will the first matching case’s block run, but so will all the co…
  8. 8
    PHP offers a short-hand syntax to conditionally return a value. Before learning it, let’s consider some example code: $isClicked = FALSE; if ( $isClicked ) { $link_color = “purple”; } else { $…
  9. 9
    So far in our conditionals, we’ve been dealing with expressions that would evaluate to boolean values in any context. In practice, any value or expression in the condition will be converted
  10. 10
    The outcomes of programs we’ve been writing so far have been predetermined. Unless we manually change our code, it will produce the same results each time it’s run. But this isn’t very realistic. P…
  11. 11
    Woah! We covered a lot in this lesson. Good work. Let’s review what we learned: + Conditionals make it possible for programs to decide how to react to a wide variety of situations. + if statements …

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo