U.S. Independence Day Deal! Unlock 25% OFF Today – Limited-Time Offer - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Zend 200-710 Exam - Topic 4 Question 103 Discussion

What is the output of the following code?$a = 3;switch ($a) {case 1: echo 'one'; break;case 2: echo 'two'; break;default: echo 'four'; break;case 3: echo 'three'; break;}
C) three
A) one
B) two
D) four

Zend 200-710 Exam - Topic 4 Question 103 Discussion

Actual exam question for Zend's 200-710 exam
Question #: 103
Topic #: 4
[All 200-710 Questions]

What is the output of the following code?

$a = 3;

switch ($a) {

case 1: echo 'one'; break;

case 2: echo 'two'; break;

default: echo 'four'; break;

case 3: echo 'three'; break;

}

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

0/2000 characters
Ines
11 hours ago
Wait, does the default case get executed if there's a match? I feel like I might be mixing that up with something else.
upvoted 0 times
...
Adell
2 months ago
I practiced a similar question last week, and I think the order of cases matters. Since $a is 3, it should definitely go to case 3.
upvoted 0 times
...
Gearldine
2 months ago
I'm not entirely sure, but I remember something about the default case being executed if no matches are found.
upvoted 0 times
...
Ettie
2 months ago
I think the switch statement checks the value of $a, so it should match case 3 and output 'three', right?
upvoted 0 times
...

Save Cancel