PHP case Keyword

❮ PHP Keywords

Example

Use case to run some code when a variable has a specified value:

<?php
$a = 3;
switch($a) {
  case 1:
    echo "One";
    break;
  case 2:
    echo "Two";
    break;
  case 3:
    echo "Three";
    break;
}
?>
Try it Yourself »

Definition and Usage

The case keyword is used to jump to a line of code when an expression has a specific value in a switch conditional.


Related Pages

The switch keyword.

Read more about the switch conditional in our PHP switch Statement Tutorial.


❮ PHP Keywords
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.