Introduction to PHP Data types

Source: Internet
Author: User

PHP supports 8 types of raw data.

Four scalar types: Boolean (Boolean), Integer (integer), float (floating-point, also known as Double), string (string).

Two types of Conformance: Array (array), object

Two special types: resource (Resource), NULL (no type)

The type of the variable is usually not set by the programmer, but rather is determined by the context in which PHP is used according to the variable.

Note: If you want to see the value and type of an expression, use the Var_dump () function. Use the GetType () function if you just want a readable type of expression for debugging purposes. To view a type, do not use GetType () and use the Is_type function.

<?php
Header("Content-type:text/html;charset=utf-8");
$a _bool=TRUE;//a Boolean
$a _str= "Foo";//A String
$a _str2= ' Foo ';//A String
$an _int= 12;//An integer
EchoGetType($a _bool);//Prints Out:boolean
EchoGetType($a _str);//Prints out:string
if(Is_int($an _int)){
$an _int+ = 4;
Echo$an _int;//Print Out:16
}
if(is_string($a _bool)){
Echo"String:$a _bool";
}
?>

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

Introduction to PHP Data types

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.