fork download
  1. <?php
  2.  
  3. function valida_variavel_zero_um($valor)
  4. {
  5. $valor = intval($valor);
  6.  
  7. if ($valor != 0 && $valor != 1)
  8. {
  9. return "inválido";
  10. }
  11.  
  12. return $valor;
  13. }
  14.  
  15. $tests = [0, 1, false, true, "0", "1", [], "", 0.0, -0.0, 1.0];
  16.  
  17. foreach ($tests as $test)
  18. {
  19. var_dump( valida_variavel_zero_um($test) );
  20. }
Success #stdin #stdout 0s 82880KB
stdin
Standard input is empty
stdout
int(0)
int(1)
int(0)
int(1)
int(0)
int(1)
int(0)
int(0)
int(0)
int(0)
int(1)