Back to questions
JuniorTheoryCommon
What does the program print?
<?php
$code = '2';
switch ($code) {
case 2:
echo 'two';
case 3:
echo 'three';
break;
default:
echo 'other';
}twothree
- Expecting
two, as if eachcaseended on its own: withoutbreak, PHP falls through and also runscase 3, up to itsbreak. - Expecting
otherbecause'2'is a string:switchcompares loosely with==, so the numeric string'2'matchescase 2.
- What does the program print if
case 2:gets its ownbreak? - Which value of
$codemakes the program printother?