PHP - switch with break statement

Introduction

breaks are mandatory if you want to exit the switch... case.

If you do not specify any, PHP will keep on executing statements, even if it encounters a new case.

Let's see a similar example, but without the breaks:

Demo

<?php 
    $title = 'Java'; 
    switch ($title) { 
        case 'Java': 
            echo "Java."; 
        case 'Twilight': 
            echo 'Uh...'; 
        case 'Lord of the Rings': 
            echo "A classic!"; 
        default: 
            echo "Dunno that one."; 
     } //from   ww w.ja va2  s . c  o m
?>

Result

Related Topic