Am I getting it? - All on your own


I wrote te following code:

    $age = 6;
    switch ($age) {
        case 1: ($age <= 6)
            echo "you should go to play!";
        case 2: ($age > 6)
            echo "you should study!";
        case 3: ($age <= 18)
            echo:"you should study!";
        case 4: ($age > 18)
            echo: "you should work!";

The result of it: Parse error: syntax error, unexpected T_ECHO on line 11

However, I got a congratulation message, saying I'm good to go.

What's wrong? Can anybody help me, please.


Not sure on PHP syntax, but your echo's are inconsistent.


I'm pretty sure they should be the first one.


You're getting the syntax for a switch statement wrong:

switch ($var) {
    case (expr1):
         // do something
    case (expr2):
        // do something else

This does the first thing if expr1 is equal to $var. There's no way to check if it is smaller than or some other inequality. To do that, you would have to check all the possibilities that it could be equal to.

Also as @cadecodes commented: the correct syntax for echo is:

echo "Your text here";