PHP Introductory Training tutorial PHP data type

Source: Internet
Author: User

PHP supports eight primitive types (type), the following brother even PHP training

A small series to give you a list:.

Four types of scalar:

String (String)

Integer (integer type)

Float (floating point type, also double)

Boolean (Boolean)

Two kinds of composite types:

Array (arrays)

Object (Objects)

Two special types:

Resource (resources)

Null (empty)

 View variable types

The GetType () function makes it easy to see the type of a variable:

<?php$var_bool = true;//a boolean$var_str = "foo"; a string$var_int = 12; Anintegerecho GetType ($var _bool); Output Booleanechogettype ($var _str); Output Stringecho GetType ($var _int);//Output integer?>

Tips

For historical reasons, if the data is float type, the GetType () function returns a double instead of float.

If you want to see the value and type of an expression, use the Var_dump () function.

 Judging variable types

If you want to determine the next logical action by judging the variable type, do not use GetType () and use the Is_type series function:

<?php$var_int = 12;//If the $var _int is of type int, this is an addition if (Is_int ($var _int)) {$var _int = $var _int+4;} echo $var _int; Output 16?>

PHP Introductory Training tutorial PHP data type

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.