Data Types for PHP

Source: Internet
Author: User

PHP is a weak type of language, Java, C language, C + + is a strong type of language;

In PHP, when we declare a variable, we do not need to set the data type, but the value to determine the type of the variable ;

Eight Big data types

4 Types of scalar data:

1. Integral type: int

An integer in memory accounts for 4 bytes, no matter how long you keep the data, it takes 4 bytes, an integer type of data, and a range of more than 2 billion;

2. Float Type: float

Single precision: A decimal number after the decimal point, accounting for 4 bytes

Double: there are several decimal places after the decimal point, accounting for 8 bytes

3. Strings string

Definition string: Single quote ' double quotation mark ' delimiter <<<

The difference between single and double quotation marks

• Double quotes inside can parse variables, single quotes will be inside the output intact;

Echo ' $result '; echo "$result";

• Escape character \ will \ Transfer characters after the intact output

Single quotation mark: \ $result

Double quotes: $result

• It is recommended to use single quotes, double quotes to determine whether there are variables, execution speed is slower than single quotes

• Single quotes cannot be nested with single quotes, double quotes cannot be nested double quotes

PHP delimiter <<<

Requirements: In PHP files, you need to output a bit of JavaScript code;

Idea: The browser shows the result of the parsed PHP file, returning a piece of JavaScript code to the browser;

<?php    $str =<<<    <script>           alert (' Welcome to PHP ');     </script>eot;     echo $str;     Var_dump ($STR);  <<< EoT at the back of the letter, indicating the beginning of the string;   EoT; to shelf the end of the string;?>

4. Boolean bool

True False

When converting to a bool value, the case is considered false:

False itself;

Integer value 0;

Floating-point value 0.0;

The empty string and the string "0";

an empty array;

Objects that do not include any member variables;

NULL;

A SimpleXML object without any marks;

Two types of composite data

5. Array arr

$arr =array (1,2,3,4,5);  An array can hold multiple values var_dump ($arr); Echo ' <br/> ';

In PHP, the array () function is used to create arrays;

Indexed array: An array with a numeric index;

$cars =array ("Volvo", "BMW", "ASSB"), or$cars[0]= "Volvo", $cars [1]= "BMW"; $cars [2]= "ASSB"; echo "I like". " $cars [0]. ",". $cars [1]. "and" $cars [2] ".";

Associative array: An array with the specified key;

$aga =array ("Peter" = "The", "ben" = "Notoginseng", "Joe" = "or$age["), "Peter"]= "a", $age [' Ben ']= "Notoginseng"; $age [' Joe ']= ' "Echo" Peter is "$age [Peter]." Years-old. "

Multidimensional array: An array that contains one or more arrays

6. Object Obiect

$db =new mysqli (' localhost ', ' root '); Var_dump ($db); Echo ' <be/> ';

  

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.