<?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) ); }
PD9waHAKCmZ1bmN0aW9uIHZhbGlkYV92YXJpYXZlbF96ZXJvX3VtKCR2YWxvcikKewogICAgaWYgKCR2YWxvciAhPT0gMCAmJiAkdmFsb3IgIT09IDEpCiAgICB7CiAgICAgICAgcmV0dXJuICJpbnbDoWxpZG8iOwogICAgfQoKICAgIHJldHVybiAkdmFsb3I7Cn0KCiR0ZXN0cyA9IFswLCAxLCBmYWxzZSwgdHJ1ZSwgIjAiLCAiMSIsIFtdLCAiIiwgMC4wLCAtMC4wLCAxLjBdOwoKZm9yZWFjaCAoJHRlc3RzIGFzICR0ZXN0KQp7CiAgICB2YXJfZHVtcCggdmFsaWRhX3ZhcmlhdmVsX3plcm9fdW0oJHRlc3QpICk7Cn0=