Just another little function which doesn't exist yet, but I find mighty useful, especially when working with AJAX and APIs.
<?php
function boolval($in, $strict=false) {
$out = null;
if (in_array($in,array('false', 'False', 'FALSE', 'no', 'No', 'n', 'N', '0', 'off',
'Off', 'OFF', false, 0, null), true)) {
$out = false;
} else if ($strict) {
if (in_array($in,array('true', 'True', 'TRUE', 'yes', 'Yes', 'y', 'Y', '1',
'on', 'On', 'ON', true, 1), true)) {
$out = true;
}
} else {
$out = ($in?true:false);
}
return $out;
}
?>
It may be pretty inefficient, but it does the job.