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

Control Flow: Switch Forum

View Course » View Exercise

327 points
Submitted by
about 4 years ago

Example case is not correct

On line 19, it should be

echo $i.' is somewhere between 1 and 5.';

otherwise it will just print $i, instead of showing its value.

or else double quotes which evaluates will also do :

echo "$i is somewhere between 1 and 5"

0 votes


You're right in that the value of $i is not inserted into the string, but I think that is intentional: the message printed to the document is:

$i is somewhere between 1 and 5.

– the message is talking about the variable $i.

3117 points
Submitted by
Alex J
about 4 years ago


52565eeb80ff337232001e7d_158831513 brennanpringle_4f151ba89c99ab0001018 about 4 years ago

By any chance do you happen to know why an escape sequence is required for the $i variable when using double quotation marks, but not needed when using single quotation marks?

Picture Alex J about 4 years ago

That’s simply because single-quoted strings are printed verbatim, without interpreting anything.

0 votes


switch ($i) {
case 0:
echo '$i is 0.';
case 1:
case 2:
case 3:
case 4:
case 5:
echo '$i is somewhere between 1 and 5.';

1228 points
Submitted by
almost 4 years ago