Hi my friends . In this sample $x=1 and should run case 1 echo one . But run all of case . Why print all of cases ? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

Hi my friends . In this sample $x=1 and should run case 1 echo one . But run all of case . Why print all of cases ?

22nd Jun 2018, 4:56 AM
Seyyed Reza Rastbod
4 Réponses
+ 2
Add break statements to the end of each case
22nd Jun 2018, 5:14 PM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
+ 2
you are most likely missing a break statement
22nd Jun 2018, 6:27 AM
hinanawi
hinanawi - avatar
+ 1
code is : $x=1; switch ($x) { case 1: echo "One"; case 2: echo "Two"; case 3: echo "Three"; default: echo "No match"; }
22nd Jun 2018, 4:42 PM
Seyyed Reza Rastbod
0
Can you provide code?
22nd Jun 2018, 5:54 AM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar