3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function test_switch($value) { $matches = ""; switch ($value) { case 0: $matches .= "0 "; } switch ($value) { case 1: $matches .= "1 "; } switch ($value) { case true: $matches .= "true "; } switch ($value) { case false: $matches .= "false "; } switch ($value) { case null: $matches .= "null "; } switch ($value) { case "0": $matches .= "'0' "; } switch ($value) { case "1": $matches .= "'1' "; } return $matches; } foreach (array(0, 1, true, false, null, "0", "1") as $value) { $matches = test_switch($value); var_dump(array('value' => $value, 'matches' => trim($matches))); }
based on HQq6I
Output for 4.3.0 - 7.2.0
array(2) { ["value"]=> int(0) ["matches"]=> string(16) "0 false null '0'" } array(2) { ["value"]=> int(1) ["matches"]=> string(10) "1 true '1'" } array(2) { ["value"]=> bool(true) ["matches"]=> string(10) "1 true '1'" } array(2) { ["value"]=> bool(false) ["matches"]=> string(16) "0 false null '0'" } array(2) { ["value"]=> NULL ["matches"]=> string(12) "0 false null" } array(2) { ["value"]=> string(1) "0" ["matches"]=> string(11) "0 false '0'" } array(2) { ["value"]=> string(1) "1" ["matches"]=> string(10) "1 true '1'" }