PHP Knowledge points-data types and operators

Source: Internet
Author: User
Tags scalar

First, the data type

A, the whole division
Scalar type: int--reshape, float--decimal, string--string, bool--Boolean two values
Composite type: Array, object
Special type: null, resouce

2, integer type int, an integer

3, 3 kinds of integer notation
Decimal notation: 123:
$n 1 = 123;
Octal notation: 0123
$n 2 = 0123;
Hexadecimal notation: 0x123
$n 3 = 0x123;

4. Floating-point type: float, double, real

There are two ways to do this:
$v 1 = 1.234; With a decimal point, which is the floating type
$v 2 = 1.234e3;//means: 1.234 times 10 of 3 times, or 1234, with E in the form of floating-point numbers
$v 3 = 1234e3;//The result value is 1234000, but it is also a floating-point number.
Note: Floating-point numbers should not be compared directly to size
The usual practice: multiply the number of digits by 10, for example, the precision requires 3 digits, then multiply by 103 times the square
When the result of an integer operation exceeds the range of an integer, it is automatically converted to a floating-point number.

5. String type: string

6. Boolean type:bool, Boolean

7. Array type: Arrar

8, Object Type objects : usually refers to their own definition of the object, pure grammar.

9. Resource type resource: refers to a reference to external data.

10, NULL type NULL

B, type conversion
A, auto-conversion: It converts data that is not handled by the operator into data that can be processed, depending on the needs of the operator in various operations.
if (data) {}: converted to bool type
Arithmetic operators: converting to numeric types
Join operators: Convert to String type
Comparison operator: To Boolean type or numeric type
If there is at least one boolean on both sides, the other side will turn to Boolean and compare
Otherwise, the comparison is converted to a number
A particularly common conversion, whether auto-cast or cast, is to convert the string to a number:
"5" ==>> 5//integer
"5.5" ==>> 5.5 floating point
"5abc" ==>> 5 integers
"5.5ab" ==>> 5.5 floating point
"Abc5" ==>> 0 integers
"abc" ==>> 0 integers
"" ==>> 0
Start from the left until the first character that is not a number ends

B, cast : It is the syntax to convert a data to another type of data
Output data type:
The ability to output the full information of a variable: var_dump ()
Gets the type name of a variable: GetType ()
Isset (), Empty (), unset ();
Isset () Determines whether a variable has data:
Empty () to determine whether a data is empty: close to our daily concept (Nothing is empty)
Unset (): Destroys (deletes) a variable.
IS_XX type () series function: Determines whether a data is of a certain type, including:
Is_int (), Is_float (), Is_numeric (), Is_bool (), Is_array (), Is_scalar ()--detects if a variable is a scalar:
Is_numeric () to: 3, 3.5, "3", "3.14" is true
Is_scalar (): Determines whether it is a scalar type (that is, Int,float,stirng,bool)

Second, operator

1. Arithmetic operators
There are several: +-*/% + +--
Note: Pay attention to the remainder operation%, first take the whole, then take the remainder
$v 1 = 7.5 3; The result is: 1
$v 2 = 7.5 3.5; The result is: 1

2. Self-increment decrement operator:
General: The number is self-added 1 or self-minus 1.
String: Only self-increment, and the effect of self-increment is "next character"
Boolean Increment decrement invalid
Null decrement is invalid, increment result is 1

3, pre-Gaga and post-gaga differences:
Before + +: The increment operation of the variable is done first, then the value of the variable is taken to participate in other operations.
Post + +: Store The value of the original variable temporarily, increment the value of the variable, and then participate in another operation with the temporarily stored value.

4. Comparison operators:

Include:> >= < <=! = = = value Size comparison (judging) = = = value size and data type are compared!==
The difference between = = and = = =:
= = Comparison of value size (judging)
= = = value size and data type are compared

5. Shift Operators
Left-shift Operation:<< a << n;//a is a number to be moved, it can also be a normal number, but by binary, n is a specified number of bits to move
Right-shift Operation:>> a >> n;//a is a number to be moved, it can also be a normal number, but by binary, n is a specified number of bits to move

6. Condition (trinocular) Operator:
A generic operator requires 2 data to participate
There are several operators that require only one data participation: + +,--!
The
A conditional operator requires at least 3 data to participate!
The form is:
Data 1? Data 2: Data 3
Typically, data 1 should eventually be a Boolean value (if not, it will be used as a Boolean value).

Meaning:
If data 1 is true, the result of the operation is data 2, otherwise the result of the operation is data 3

7. Error control Operator:@ is usually used in front of an expression "possibly" where the error occurred-the most common scenario is to connect to the database.

PHP Knowledge points-data types and operators

Related Article

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.