- var_dump: documentation ( source)
<?php
$convertQ = function ($str) {
if ('No' === $str || '0' == $str) {
return 'no';
}
if ('Yes' === $str || '1' == $str) {
return 'yes';
}
if ('Unsure' === $str) {
return 'maybe';
}
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 'yes'
var_dump($convertQ('Yes')); // expect 'yes', get 'yes'
var_dump($convertQ('Unsure')); // expect 'maybe', get 'maybe'
var_dump($convertQ('a')); // expect thrown error, get error thrown