<?php
function valida_variavel_zero_um($valor){
if((empty($valor)) OR
(strlen($valor) != 1) OR
($valor != 1 && $valor != 0)){ return "INVALIDO";
}else{
return $valor;
}
}
$tests = [0, 1, false, true, "0", "1", [], "", 0.0, -0.0, 1.0];
foreach ($tests as $test)
{
var_dump( valida_variavel_zero_um
($test) ); }
PD9waHAKCmZ1bmN0aW9uIHZhbGlkYV92YXJpYXZlbF96ZXJvX3VtKCR2YWxvcil7CiAgICAgaWYoKGVtcHR5KCR2YWxvcikpIE9SIChzdHJsZW4oJHZhbG9yKSAhPSAxKSBPUiAoJHZhbG9yICE9IDEgJiYgJHZhbG9yICE9IDApKXsKICAgICAgICByZXR1cm4gIklOVkFMSURPIjsKICAgICB9ZWxzZXsKICAgICAgICByZXR1cm4gJHZhbG9yOwogICAgIH0KfQoKJHRlc3RzID0gWzAsIDEsIGZhbHNlLCB0cnVlLCAiMCIsICIxIiwgW10sICIiLCAwLjAsIC0wLjAsIDEuMF07Cgpmb3JlYWNoICgkdGVzdHMgYXMgJHRlc3QpCnsKICAgIHZhcl9kdW1wKCB2YWxpZGFfdmFyaWF2ZWxfemVyb191bSgkdGVzdCkgKTsKfQo=