<!DOCTYPE HTML>
<html lang="es-MX">
  <head>
    <title>
      Curso PHP - Cambiar el tipo de la variable con settype
    </title>
  </head>
  <body style="background-image:url('images/logoBG.jpg');">
    <?php
      /* settype()
       * (PHP 3, PHP 4, PHP 5)
       * settype -- Definir el tipo de una variable
       * Descripción
       * bool settype ( mixed &var, string tipo )
       * 
       * Definir el tipo de la variable var a tipo. 
       * Los posibles valores de tipo son: 
       * "boolean" (o, desde PHP 4.2.0, "bool") 
       * "integer" (o, desde PHP 4.2.0, "int") 
       * "float" (únicamente posible desde PHP 4.2.0, para versiones
       * anteriores use la variante obsoleta "double") 
       * "string" 
       * "array" 
       * "object" 
       * "null" (desde PHP 4.2.0) 
       * Devuelve TRUE si todo se llevó a cabo correctamente,
       * FALSE en caso de fallo. 
       */

      $MiVar = 3.14;
 
      print( "<p style='font:14pt helvetica;'>" );
      print(    gettype( $MiVar ) );   // Double
      print(   " es $MiVar<br />" );   // 3.14  

      settype( $MiVar, "string" );
      print(    gettype( $MiVar ) );   // String
      print(   " es $MiVar<br />" );   // 3.14  

      settype( $MiVar, "integer" );
      print(    gettype( $MiVar ) );   // Integer
      print(   " es $MiVar<br />" );   // 3

      settype( $MiVar, "double" );
      print(    gettype( $MiVar ) );   // Double
      print(   " es $MiVar<br />" );   // 3.0

      settype( $MiVar, "boolean" );
      print(    gettype( $MiVar ) );   // Boolean
      print(   " es $MiVar<br />" );         // 1

      settype( $MiVar, "double" );
      print(    gettype( $MiVar ) );   // Double
      print(   " es $MiVar" );   // 1.0

      print( "</p>" );
    ?>
  </body>
</html>