This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Control Flow: Switch Forum

View Course » View Exercise

361 points
Cf66ed9eb3c327fa577496cbb6c75870?s=140&d=retro
Submitted by
Drew Caddens
about 4 years ago

Parse error: syntax error, unexpected T_CASE, expecting ':' or '{' on line 10

<?php
$a=3;
switch ($a)
case 1:
case 2:
case 3:
echo '$a is somewhere between 1 and 3';
break;

         case 4:
        case 5:
        echo '$a is somewhere between 1 and 5';

    break;
    case 6:
    case 7:
        echo '$a is somwhere either 6 or 7';

    break;

    default:
        echo 'I have no idea how much $a is';

        break;
endswitch

2 votes

permalink

<?php
$i = 2;
switch (true):
case 1:
echo "wrong!";
break;
case 3:
echo "wrong!";
break;
case 4:
echo "wrong!";
break;
default:
echo "Correct!";
endswitch;
?>

USE THIS TO FINISH THIS ONE YOUR WELCOME

487 points
48eae9309fc92e8369d110aa8ce618a4?s=140&d=retro
Submitted by
SSalzl
about 4 years ago