PHP Day 6: Booleans, More Operators, and Conditional Statements

This five-minute video covers the basics of boolean values, comparison operators, logical operators, and conditional statements (using if, else, elseif, and switch).

Links for PHP Day 6: Booleans, More Operators, and Conditional Statements

Booleans:

  • PHP: Booleans
  • Note: it’s been brought to my attention (thanks to a certain database-programming boyfriend) that I really skipped over explaining boolean values. I was a little too eager to get to the conditional statements, I guess. ;) The link above should help. If something isn’t clear, though, just let me know.

Operators:

Conditional statements:

Since this stuff was pretty simple, I found that I really didn’t need any reference sites other than the PHP manual.

Posted on February 7th, 2007 | Leave a comment | Trackback URL

3 Comments

  1. hobs

    February 8th, 2007

    Question: I was watching your thing about cases, what happens if you want something like greater than 5 as a case, instead of just 5?

  2. LearningNerd

    February 8th, 2007

    Good question! I didn’t want to spend too much time on it now, so I just skimmed over how it basically works.

    But I looked it up on the PHP manual, and I found the answer in a comment on the page for Switch. So, switch works by matching one value against all the values given after each case. And “$x > 5” has a value of true or false, right? So to match the values against each other, you’d have to put “true” after switch:

    $x = 7;
    switch(true) {
    case $x == 5:
    echo 'equals five';
    break;
    case $x > 5:
    echo 'greater than five';
    break;
    case $x < 5:
    echo 'less than five';
    break;
    }

    It makes more sense to me to just use if and elseif, but I guess this does have its uses.

  3. hobs

    February 9th, 2007

    Awesome!

Share Your Thoughts