Summary and sharing of common data types in PHP

Source: Internet
Author: User

PHP Data Type

PHP supports eight primitive types ).

Four scalar types:
String (string)
Float (float, also double)
Boolean (boolean)

Two composite types:

Two special types:

View variable types

The gettype () function allows you to conveniently view the type of a variable:
Copy codeThe Code is as follows:
<? Php $ var_bool = TRUE; // a boolean $ var_str = "foo"; // a string $ var_int = 12; // an integerecho gettype ($ var_bool ); // output booleanecho gettype ($ var_str); // output stringecho gettype ($ var_int); // output integer?> (PS: T good php q buckle: 276167802, verification: csl)


For historical reasons, for float data, the gettype () function returns double instead of float.
To view the value and type of an expression, use the var_dump () function.

Judge variable type

To determine the next logical action by determining the variable type, use the is_type series functions instead of gettype:
Copy codeThe Code is as follows:
<? Php $ var_int = 12; // if $ var_int is of the int type, add if (is_int ($ var_int) {$ var_int = $ var_int + 4;} echo $ var_int; // output 16?>

The above is a summary of the PHP Data Types in this article. I hope this article will help the majority of php developers. Thank you for reading this article.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.