Php (3) PHP variable type

Source: Internet
Author: User
Php (3) PHP variable types 1. PHP variable types:

<1> scalar type:

Boolean (boolean)

Integer)

Float (float type, also "double ")

String (string)

<2> compound type:

Array)

Object)

<3> Special types:

Resource)

NULL

PS: php variable types do not need to be declared. php automatically determines the type based on the context of the program running. is it very smart? Awesome

To view the value of an expression, you can use the var_dump () function ().

(1). boolean (boolean)

Only two values are true or false, which are case-insensitive. all values other than 0 are true and 0 is false.

Boolean (boolean) is often used for process control for condition judgment.

Example:

[php]  
 

2. integer)

The integer value can be specified in decimal, hexadecimal, or octal notation.

Example:

 

?>

3. float (float type, also "double ")

Floating-point numbers (also called floating-point numbers, double-precision numbers or real numbers) can be defined using any of the following syntax:

Example:

[php]  
  

(4) string (string)

There are three methods to define a string: single quotes, double quotation marks, and delimiters.

For example:

[Php]
  "; Echo $ B; echo"
"; Echo $ c;?>

Variable parsing:

Single quotes: If the definition content contains variables, the variable name is directly output, rather than the content.

Double quotation marks: If the defined content includes variables, the content is output directly.

Delimiters: If the defined content includes variables, the content is output directly.

You can use {} to specify the variable range in double quotation marks and delimiters.

[php]  
  

(5) array () (array) definition

Array ([key =>]

Value

,...

)

// The key can be integer or string.

// Value can be any value

For example:

[php]  
   "bar", 12 => true);  echo $arr["foo"]; // bar  echo $arr[12];    // 1  ?>

(6) object)

To initialize an object, use the new statement to instance the object to a variable.

Example:

[Php]
  Do_foo ();?>

(7) resource)

Waiting for writing...

(8) NULL

A special NULL value indicates that a variable does not have a value but does not exist. The only possible value of the NULL type is NULL. '

The variable is considered NULL in the following cases:

The value is NULL.

Not assigned.

Unset ().

For example:

[php]  
  

Two related functions:

Is_null (): determines whether the variable is NUll.

Unset (): delete variable declaration

The above is the php (3) PHP variable type content. For more information, please follow the PHP Chinese network (www.php1.cn )!

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.