Data Types for PHP

Source: Internet
Author: User

I. Classification of data types (three major classes eight small classes) 1. Scalar data types
    • INT linear integer, can have decimal, octal, hexadecimal

<? PHP    // decimal   $v 1=255;    Echo $v 1; // 255   //Eight binary------starts with 0 (the output is automatically converted to a 10-binary integer)   $v 2=076;    Echo $v 2; //    16 binary-----starts with 0x (the output is automatically converted to a 10-binary integer)   $v 3=0xff;    Echo $v 3; // 255?>

    • Float with the number of decimal points, can be defined by ordinary methods, you can also use scientific notation, remember that decimals can not be arbitrarily compared between the size

<? PHP   // defining floating Types  $v 1=3.33;   Echo $v 1; // 3.33  //Scientific counting method  $v 2=1.22e+9;   Echo $v 2; // 1220000000?>

<?  If(0.7-0.3==0.4) {     echo ' yes ';} Else {     echo ' no '// output is no, indicating that it is not possible to compare the size of two decimal points?>

    • Boolean two digits ture or false, set up or not set up
    • String strings are 0 or more characters enclosed in single or double quotation marks

① a string defined using single quotation marks

Characters that can be escaped have \ \ (backslash) \ ' (single quote)

A variable of a string defined by single quotation marks cannot resolve its value

<?  $num=10// single quotation mark defined string $strA= ' act\\ions spe\ ' ak Louder than Words $num 'echo$strA; // act\ions SPE ' ak Louder than Words$num?>

② a string defined using double quotation marks

Characters that can be escaped have \ ' (double quotation marks) \ t (tab) \ r (carriage return) \ n (line break) \ \ (backslash) \$ ($ character)

The value of a variable in a string defined by double quotation marks can be resolved

<?  $num=10// double quotation mark defined string $strB= "Act\\ions spe\" AK lou\ $der than Words$num"echo$strB; // act\ions SPE "AK lou$der than WORDS10?>

③heredoc defines a string that defines a large segment of text

2. Composite data types
    • Array arrays, divided into indexed arrays (subscripts are indexes) and associative arrays (subscripts are strings)

    • Object objects
3. Special data types
    • Null has only one value null
    • The resource resource data type is a special variable that the programmer has no way of directly defining a resource and must use PHP to provide a function to get the resource

Ii. Conversion of data types
    • Automatic conversion

    • Forced conversions

Data Types for PHP

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.