Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html lang="es">
- <head>
- <meta charset="utf-8">
- <title>Booleanos</title>
- </head>
- <body>
- <h1>Conversion a False</h1>
- <p>
- PREGUNTA: ¿Cuántas situaciones extrañas, o errores, puede notar en las mútiples posibilidades de ejecución de este script?
- </p>
- <?php
- //Todos los valores contenidos en el siguiente arreglo se evaluan a false
- $valores_falsos = [
- false, //false mismo
- 0, //cero
- 0.0, //cero en punto flotante
- "", //cadena vacia
- "0", //cero en cadena de texto
- [], //arreglo vacio
- new stdClass(), //objeto vacio, sin ninguna propiedad
- null //nulo
- ];
- ?>
- <ol>
- <?php
- /**
- * La funcion count(array) devuelve el numero de elementos que tiene un arreglo
- */
- for ($i=0; $i<=count($valores_falsos); $i++) {
- ?>
- <li>
- Valor: <?php var_dump($valores_falsos[$i]); ?><br>
- <?php if ($valores_falsos[$i]) { ?>
- No es falso!!!
- <?php } else { ?>
- Es evaluado a FALSE
- <?php } ?>
- </li>
- <?php
- }
- ?>
- </ol>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement