<?php
function valida_variavel_zero_um($valor)
{
if ($valor != 0 && $valor != 1)
{
return "inválido";
}
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) ); }
PD9waHAKCmZ1bmN0aW9uIHZhbGlkYV92YXJpYXZlbF96ZXJvX3VtKCR2YWxvcikKewogICAgJHZhbG9yID0gaW50dmFsKCR2YWxvcik7CiAgICAKICAgIGlmICgkdmFsb3IgIT0gMCAmJiAkdmFsb3IgIT0gMSkKICAgIHsKICAgICAgICByZXR1cm4gImludsOhbGlkbyI7CiAgICB9CgogICAgcmV0dXJuICR2YWxvcjsKfQoKJHRlc3RzID0gWzAsIDEsIGZhbHNlLCB0cnVlLCAiMCIsICIxIiwgW10sICIiLCAwLjAsIC0wLjAsIDEuMF07Cgpmb3JlYWNoICgkdGVzdHMgYXMgJHRlc3QpCnsKICAgIHZhcl9kdW1wKCB2YWxpZGFfdmFyaWF2ZWxfemVyb191bSgkdGVzdCkgKTsKfQ==