CKTIS / PHP
Keyword case
Mark a possible entry point in switch.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
case $label:Mark a possible entry point in switch. The switch expression is compared loosely to each case expression until a match, so numeric string "2" can select case 2. After entry PHP runs following statements, including subsequent cases, until break or the end. A case declaration also names an enum member.
$seen=[];
switch ("2") { case 2: $seen[]="match"; case 3: $seen[]="next"; break; default: $seen[]="none"; }
echo json_encode($seen);
["match","next"]
Examples
<?php
$seen=[];
switch ("2") { case 2: $seen[]="match"; case 3: $seen[]="next"; break; default: $seen[]="none"; }
echo json_encode($seen);
Result
["match","next"]