3v4l.org

run code in 300+ PHP versions simultaneously
<?php $convertQ = function ($str) { switch ($str) { case 0: case 'No': return 'no'; case 1: case 'Yes': return 'yes'; case 'Unsure': return 'maybe'; default: throw new \InvalidArgumentException('Unaccounted for value for questionnaire field: ' . $str); } }; var_dump($convertQ(0)); // expect 'no', get 'no' var_dump($convertQ('No')); // expect 'no', get 'no' var_dump($convertQ(1)); // expect 'yes', get 'no' var_dump($convertQ('Yes')); // expect 'yes', get 'no' var_dump($convertQ('Unsure')); // expect 'maybe', get 'no' var_dump($convertQ('a')); // expect thrown error, get 'no'

preferences:
55.41 ms | 404 KiB | 5 Q