Home > Backend Development > PHP Tutorial > Summary of JavaScript data types PHP eight basic data types

Summary of JavaScript data types PHP eight basic data types

WBOY
Release: 2016-07-29 08:45:23
Original
921 people have browsed it

Four scalar types:

  • boolean (Boolean)
  • integer (integer)
  • float (Floating point, also called double)
  • string (String)

Two composite types:

  • array (Array)
  • object (Object)

Finally there are two special types:

  • resource  (Resource)
  • NULL (NULL)

To ensure the readability of the code, this manual also introduces some pseudo-types:

  • mixed
  • number
  • callback

and pseudo variables $....

You may also read some references to the "double" type. In fact, double and float are the same, and for some historical reasons, these two names existed at the same time.

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

Note: If you want to check the value and type of an expression, use var_dump().

If you just want to get an easy-to-read type expression for debugging, use gettype(). To check a certain type, don’t use gettype(), but use is_type function. Here are some examples:

Copy code The code is as follows:


$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 $bool is a string, print it out
// (does not print out anything)
if (is_string($a_bool)) {
echo "String: $a_bool";
}
?>


If you want to force a variable to a certain type, you can use cast or settype () function.

Note that variables will exhibit different values ​​on specific occasions depending on their type at the time. See Type Tricks for more information. Additionally, you can refer to the PHP Type Comparison Chart for examples of how different types compare to each other.

The above has introduced a summary of the eight basic data types of PHP in JavaScript data types, including the content of JavaScript data types. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template