PHP Learning note--3. operator

Source: Internet
Author: User

Directory:

PHP Learning note--1. variables

PHP Learning note--2. Constants

PHP Learning note--3. operator

1. Arithmetic operators

+-*/% (modulo)

%: The positive and negative values of the remainder are determined by dividend

2. Comparison operators

= = = > < >= <= = = =!==

= = = The value and type of the variable is compared to!==

Note: When comparing different types

PHP will first convert the previous variable to the same type as the Sing Woo, then compare

Boolean-string true-> ' 1 ' false-> "

String--Number ' 123abc456 '->123

String--Boolean ' or ' 0 '->false

Number, Boolean 0 or 0.0->false negative also true

Numeric-string As-is output

3. String Operators . (stitching)

$str 1 = ' Hello '; $str 2 = "; $str 3 = ' world '; Echo $str 1. $str 2. $str 3;    // Hello world//Note: $str 1 than Echo, $str 2, $str 3; more efficient, eliminating the stitching process

4. Assignment Operators =

5. Logical operators

|| (or) && (with)! (anti) XOR (XOR)

①&& (and) priority is higher than | | Or

Use parentheses to make logic clearer when ② multiple conditions

③xor (XOR) means that a true one must be false and the return value is True

④ The conditional judgment in a logical way,

when a condition is established (or)/not established (with), the latter condition is no longer judged , which is called the ' short circuit characteristic '

// Example: $a = 3; $b = 5; if (($a = 8) | | ($b = 9)) {    $a++    ; $b+ +;} Echo $a,$b;    // 9 6//Note: $b = 9 in the condition is not judged

6. Ternary operators ?:

Condition? Statement 1: Statement 2;

Execute statement 1 when condition is true

Execute Statement 2 when condition is false

NOTE: The If statement is also achievable and more efficient

7. Bitwise operators //understanding

& (with) | (or) ^ (XOR) << (shift left) >> (shift right)

Take 0 as false, and each one does the operation with, or, or XOR

Example: 12&5 =>4

0000 1100

5 = 0000 0101
-----------------
4 =>0000 0100

Example: 5<<1 =>10

5 =>0000 0101
-----------------
Ten =>0000 1010

Example: 5>>1 =>2

5 =>0000 0101
-----------------

2 = 0000 0010

8. Supplemental Knowledge //understanding

① binary

Only 0 12 cardinality

Example: 16+0+0+2+0

From high to Low 4 3 2 1 0

10010

Then the decimal 18 is converted to binary 0001 0010

② octal

Base is 0~7

Add 0,php to the number before the output is eight binary

Example: 023 =>19

Note: When 0239 is present, because the octal number is only possible between 0~7,

So PHP will ignore 9, still output 19

③ Hex

Base for 0~9 a~f =>0~15

Add 0x,php to the number before the output is 16 binary

Example: 0x1c =>28

@zhnoah
Source: http://www.cnblogs.com/zhnoah/
This article is owned by me and the blog Park, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original
The right to pursue legal liability.

PHP Learning note--3. operator

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.