Advertisement
ryvanyo

Booleanos - 02.php

Mar 4th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!doctype html>
  2. <html lang="es">
  3.     <head>
  4.         <meta charset="utf-8">
  5.         <title>Booleanos</title>
  6.     </head>
  7.     <body>
  8.         <h1>Conversion a False</h1>
  9.         <p>
  10.             PREGUNTA: ¿Cuántas situaciones extrañas, o errores, puede notar en las mútiples posibilidades de ejecución de este script?
  11.         </p>
  12.         <?php
  13.         //Todos los valores contenidos en el siguiente arreglo se evaluan a false
  14.         $valores_falsos = [
  15.             false,          //false mismo
  16.             0,              //cero
  17.             0.0,            //cero en punto flotante
  18.             "",             //cadena vacia
  19.             "0",            //cero en cadena de texto
  20.             [],             //arreglo vacio
  21.             new stdClass(), //objeto vacio, sin ninguna propiedad
  22.             null            //nulo
  23.         ];
  24.         ?>
  25.         <ol>
  26.         <?php
  27.         /**
  28.          * La funcion count(array) devuelve el numero de elementos que tiene un arreglo
  29.          */
  30.         for ($i=0; $i<=count($valores_falsos); $i++) {
  31.         ?>
  32.             <li>
  33.                 Valor: <?php var_dump($valores_falsos[$i]); ?><br>
  34.                 <?php if ($valores_falsos[$i]) { ?>
  35.                     No es falso!!!
  36.                 <?php } else { ?>
  37.                     Es evaluado a FALSE
  38.                 <?php } ?>
  39.             </li>
  40.         <?php
  41.         }
  42.         ?>
  43.         </ol>
  44.        
  45.     </body>
  46. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement