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