4.2.46. Switch To Match

Transforms a switch() into a match() expression.

The switch() syntax must have each of the cases assigning the same variable (or similar). There should not be any other operation, besides break;

4.2.46.1. Before

<?php
    switch($a) {
        case 1:
            $b = '1';
            break;
        case 2:
            $b = '3';
            break;
        default:
            $b = '0';
            break;
    }
?>

4.2.46.2. After

<?php
    $b = match($a) {
        1 => '1',
        2 => '3',
        default => '0'
    };
?>

4.2.46.3. Suggested Analysis

4.2.46.5. Reverse Cobbler

4.2.46.6. Specs

Short Name

Structures/SwitchToMatch

Exakat version

2.3.0

Available in

Entreprise Edition, Exakat Cloud