PHP learning (4) -- data type

Source: Internet
Author: User
: This article mainly introduces PHP learning (4)-Data Types. For more information about PHP tutorials, see. PHP supports eight types of raw data.

Four scalar types: (the scalar type is the basic type)

  • Boolean (boolean)
  • Integer)
  • Float (float, also called double) (for historical reasons, float is also called double. php does not have single precision or double precision)
  • String (string type belongs to the scalar type in PHP and belongs to the class type in Java)

Two composite types:

  • Array)
  • Object)

There are two special types:

  • Resource)
  • NULL (no type)

The type of a variable is generally not set by the programmer. to be exact, it is determined by PHP at runtime based on the context used by the variable.

To view the value and type of an expression, use the var_dump () function.
If you just want to get an easy-to-understand expression of the type for debugging, use the gettype () function. To view a type, use the is_type function instead of gettype.

Example:


  "; // prints out:  booleanecho gettype($a_str)."
"; // prints out: stringecho gettype($an_int)."
"; // prints out: integerecho gettype($a_float)."
"; // prints out: double// If this is an integer, increment it by fourif (is_int($an_int)) { echo"an_int = ".$an_int."
"; $an_int += 4; echo"an_int = ".$an_int."
";}// If $bool is a string, print it out// (does not print out anything)if (is_string($a_str)) { echo"String: $a_str"."
";}echo var_dump($a_float, $a_bool, $a_str, $an_int);?>

Output:

booleanstringintegerdoublean_int = 12an_int = 16String: foofloat(3.14) bool(true) string(3) "foo"int(16)

Description of gettype () in the php Manual (please zoom in to see ?) :

For specific use of each type, please refer to the official PHP Manual. here I am only a reference.

'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
  • '). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script

    The above introduces PHP learning (4)-data type, including the content, hope to be helpful to friends who are interested in PHP tutorials.

    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: info-contact@alibabacloud.com 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.