Basic PHP knowledge (2)

Source: Internet
Author: User
Automatic data type conversion: 1. After the integer type is added or subtracted, it is still an integer type. If the integer type can be divisible, the result is an integer type; otherwise, the result is a real type; 2. During addition, subtraction, multiplication, division, and division of integer and real types, the integer type is converted to the real type, and the calculation result is still the real type. 3. When a string is involved in the operation, it is truncated from the string to the first character to the phase

Automatic data type conversion: 1. After the integer type is added or subtracted, it is still an integer type. If the integer type can be divisible, the result is an integer type; otherwise, the result is a real type; 2. During addition, subtraction, multiplication, division, and division of integer and real types, the integer type is converted to the real type, and the calculation result is still the real type. 3. When a string is involved in the operation, it is truncated from the string to the first character to the phase

Automatic data type conversion:

1. After the integer type is added or subtracted, it is still an integer type. If the integer type can be divisible, the result is an integer type; otherwise, the result is a real type;

2. During addition, subtraction, multiplication, division, and division of integer and real types, the integer type is converted to real type, and the calculation result is still real type;

3. When a string is involved in the operation, it is truncated from the string to the first character and converted to the corresponding value (either an integer or a real character );

4. When the boolean type is converted to a number, true indicates 1 false indicates 0;

Forced conversion of data types:

1. When the real type is forcibly converted to an integer, the decimal point is unsigned unconditionally (int) $

2. the integer type is forcibly converted to the real type (float) $

3. Forcibly convert an integer to a string (string) $

4. boolean type forced conversion to INTEGER (int) $ a true indicates 1 false indicates 0

5. boolean type forced conversion to string (string) $ a true indicates '1' false indicates''

6. Forcibly convert numeric type to boolean type (boolean) $ a if it is not 0, true 0 is false.

7. Forcibly convert a string to a boolean (boolean) $ a if it is not null, true if it is null, false

The following content of the operator is excerpted from (Http://www.w3school.com.cn/php/php_operators.asp)

Reference Value assignment: $ a = & $ B points the memory address of $ B to $ a. Changing $ B is equivalent to changing $.

Arithmetic Operator:

Operator Name Example Result
+ Addition $ X + $ y Sum of $ x and $ y
- Subtraction $ X-$ y Difference between $ x and $ y
* Multiplication $ X * $ y The product of $ x and $ y
/ Division $ X/$ y $ X and $ y
% Module $ X % $ y $ X remainder except $ y


Assignment operator:
Assignment Equivalent Description
X = y X = y The expression on the right sets the value for the number of operations on the left.
X + = y X = x + y Add
X-= y X = x-y Subtraction
X * = y X = x * y Multiplication
X/= y X = x/y Division
X % = y X = x % y Module

String OPERATOR:
Operator Name Example Result
. Concatenation $ Txt1 = "Hello" $ txt2 = $ txt1. "world! " Now $ txt2 contains "Hello world! "
. = Serial assignment $ Txt1 = "Hello" $ txt1. = "world! " Now $ txt1 contains "Hello world! "

Increment/decrease OPERATOR:

Operator Name Description
++ $ X Ascending $ X increment by one, and then returns $ x
$ X ++ Post-Increment Returns $ x, and increments by $ x plus one.
-- $ X Decrease before $ X minus one decrease, and then returns $ x
$ X -- Decrease Returns $ x, and then decreases by $ x.

Comparison operator:

Operator Name Example Result
= Equal $ X = $ y Returns true if $ x is equal to $ y.
=== Equality (identical) $ X ===$ y Returns true if $ x is equal to $ y and has the same type.
! = Not equal $ X! = $ Y Returns true if $ x is not equal to $ y.
<> Not equal $ X <> $ y Returns true if $ x is not equal to $ y.
! = Incomplete (completely different) $ X! ==$ Y If $ x is not equal to $ y and their types are different, true is returned.
> Greater $ X> $ y If $ x is greater than $ y, true is returned.
< Greater $ X <$ y If $ x is less than $ y, true is returned.
> = Greater than or equal $ X> = $ y Returns true if $ x is greater than or equal to $ y.
<= Less than or equal $ X <= $ y If $ x is less than or equal to $ y, true is returned.

Logical operators:

Operator Name Example Result
And And $ X and $ y If both $ x and $ y are true, true is returned.
Or Or $ X or $ y If either $ x or $ y is true, true is returned.
Xor Exclusive or $ X xor $ y If $ x and $ y have only one of them, true is returned.
&& And $ X & $ y If both $ x and $ y are true, true is returned.
| Or $ X | $ y If either $ x or $ y is true, true is returned.
! Non ! $ X Returns true if $ x is not true.

Array OPERATOR:

Operator Name Example Result
+ Union $ X + $ y $ X and $ y (but do not overwrite duplicate keys)
= Equal $ X = $ y Returns true if $ x and $ y have the same key/value pair.
=== Full $ X ===$ y True is returned if $ x and $ y have the same key/value pairs with the same sequence and type.
! = Not equal $ X! = $ Y Returns true if $ x is not equal to $ y.
<> Not equal $ X <> $ y Returns true if $ x is not equal to $ y.
! = Incomplete $ X! ==$ Y Returns true if $ x is different from $ y.

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.