Four scalar types:

  • boolean
  • integer
  • float (floating-point number, aka double)
  • string

Two compound types:

  • array
  • object

And finally two special types:

  • resource
  • NULL

This manual also introduces some pseudo-types for readability reasons:

  • mixed
  • number
  • callback

And the pseudo-variable $....

Some references to the type “double” may remain in the manual. Consider double the same as float; the two names exist only for historic reasons.

The type of a variable is not usually set by the programmer; rather, it is decided at runtime by PHP depending on the context in which that variable is used.

Note: To check the type and value of an expression, use the var_dump() function.

To get a human-readable representation of a type for debugging, use the gettype() function. To check for a certain type, do not use gettype(), but rather the is_type functions. Some examples:

<?php
$a_bool = TRUE; // a boolean
$a_str = "foo"; // a string
$a_str2 = 'foo'; // a string
$an_int = 12; // an integer

echo gettype($a_bool); // prints out: boolean
echo gettype($a_str); // prints out: string

// If this is an integer, increment it by four
if (is_int($an_int)) {
$an_int += 4;
}

// If $a_bool is a string, print it out
// (does not print out anything)
if (is_string($a_bool)) {
echo “String: $a_bool”;
}
?>

To forcibly convert a variable to a certain type, either cast the variable or use the settype() function on it.

Note that a variable may be evaluated with different values in certain situations, depending on what type it is at the time. For more information, see the section on Type Juggling. The type comparison tables may also be useful, as they show examples of various type-related comparisons.

PayPal lanzará una llave electrónica para realizar pagos móviles PayPal va a realizar un anuncio importante que hará temblar a algunas firmas asentadas en el negocio de los pagos móviles, como Square, GoPayment de I...
What is Dedicated IP You may have heard of dedicated IP web hosting as a favorable feature from a web hosting company. What does this term mean? Dedicated IP web hos...
Ranking Navegadores Julio 2012 Ranking Navegadores Julio 2012 Mozilla consigue mantener a su navegador Firefox en la segunda posición del ranking por delante de Chrome. 03/08/201...
What is a Landing page In online marketing a landing page, sometimes known as a lead capture page, is a single web page that appears in response to clicking on an advertisem...
else operator Often you'd want to execute a statement if a certain condition is met, and a different statement if the condition is not met. This is what else is f...
Problemas con Google+ Google+ ha llevado a cabo la suspensión de cuentas por el uso de nombres no reales. Pese al éxito que durante los primeros días de vida está despe...
Freepik, un motor de busqueda de diseños gratuitos, interesante herramienta para diseñadores Hace poco me han escrito sugiriendome a Freepik como un buscador de diseños gratuitos , y en así, de acuerdo a su filosofía de trabajo Freepik es ...
Google mejora las búsquedas Por si había alguna duda acerca de la consideración de Google como el mejor buscador web, ahora la compañía líder de Internet acaba de presentar una...
Total-Based Shipping Opencart Module This extension allows you to set advanced shipping rates for your shop, and can be calculated by Total with Postal Code and Category support. General...
La pagina principal del buscador Google, lista para recibir un nuevo diseño Google está preparando el lanzamiento definitivo de uno de los cambios más importantes en su diseño desde el lanzamiento de la página de inicio de su ...
PHP supports eight primitive types.
Tagged on: