In the previous article, we talked about only the data types of PHP. The so-called "cutting power without mistake" can lay a solid foundation for PHP to better learn PHP programming.
The expressions and operators in PHP are not much different from those in C language. Now, they are listed below:
┌ ── ─ ┬ ── ─
│ Operator │ example │
├ ── ─ ┼ ── ─
│ + │ Addition │ $ a + $ B │
├ ── ─ ┼ ── ─
│-│ Subtraction │ $ a-$ B │
├ ── ─ ┼ ── ─
│ * │ Multiplication │ $ a * $ B │
├ ── ─ ┼ ── ─
│/│ Division │ $ a/$ B │
├ ── ─ ┼ ── ─
│ % │ Obtain the remainder │ $ a % $ B │
├ ── ─ ┼ ── ─
│ ++ │ Incremental │ $ a ++ or ++ $ a │
├ ── ─ ┼ ── ─
│ -- │ Decrease │ $ a -- or -- $ a │
├ ── ─ ┼ ── ─
│ ==│ Equals │ $ a == 10 │
├ ── ─ ┼ ── ─
│ ===│ Equals │ $ a === 10 │
├ ── ─ ┼ ── ─
│! = │ Not equal to │ $! = 10 │
├ ── ─ ┼ ── ─
│ <│ Less than │ $ a <9 │
├ ── ─ ┼ ── ─
│> │ Greater than │ $ a> 8 │
├ ── ─ ┼ ── ─
│ <= │ Less than or equal to │ $ a <= 10 │
├ ── ─ ┼ ── ─
│ >=│ Greater than or equal to │ $ a >=1 │
├ ── ─ ┼ ── ─
│ = │ Equal value assignment operator │ $ a = 0 │
├ ── ─ ┼ ── ─
│ + = │ Addition specified operator │ $ a + = 5 │
├ ── ─ ┼ ── ─
│-= │ Subtraction specified operator │ $ a-= 1 │
├ ── ─ ┼ ── ─
│ * = │ Multiplication specified operator │ $ a * = 2 │
├ ── ─ ┼ ── ─
│ // = │ Division specified operator │ $ a/= 5 │
├ ── ─ ┼ ── ─
│ % = │ Remainder specified operator │ $ a % = 7 │
├ ── ─ ┼ ── ─
│. = │ String specified operator │ $ a. = "hello" │
├ ── ─ ┼ ── ─
│ & │ And │ $ a & $ B │
├ ── ─ ┼ ── ─
│ | │ Or │ $ a | $ B │
├ ── ─ ┼ ── ─
│ ^ │ Xor │ $ a ^ $ B │
├ ── ─ ┼ ── ─
│ ~ │ Non-│ ~ $ A (obtain the complement Code of 1) │
├ ── ─ ┼ ── ─
│ <│ Shift left │ $ a <$ B │
├ ── ─ ┼ ── ─
│ >>│ Shift to the right │ $ a >> B B │
├ ── ─ ┼ ── ─
│ And or & │ and │ $ a and $ B or $ a & $ B │
├ ── ─ ┼ ── ─
│ Or | │ or │ $ a or $ B or $ a | $ B │
├ ── ─ ┼ ── ─
│ Xor │ Xor │ $ a xor $ B │
├ ── ─ ┼ ── ─
│! │ Non-│! $ A │
└ ── ─ ┴ ── ─
┌ ── ─ ┬ ── ─ ┐
│ Symbol │ meaning │
├ ── ─ ┼ ── ─ ┤
│ $ │ Variable │
├ ── ─ ┼ ── ─ ┤
│ & │ Pointer to the variable (before the variable) │
├ ── ─ ┼ ── ─ ┤
│-> │ Method or attribute of the object │
├ ── ─ ┼ ── ─ ┤
│ => │ Element value of the array │
├ ── ─ ┼ ── ─ ┤
│? : │ Ternary operator │
└ ── ─ ┴ ── ─ ┘
Compare it with the C language. Only the "." operator is added. It connects two strings. For example, the result is hello, my baby.
<? Php
$ A = "hello ,";
$ B = "my baby .";
Echo $ a. $ B;
?>
Another symbol also makes PHP powerful. This is "$ ". It is used before A variable, indicating that it is A variable, such as $ A and $ B. So where is its role strong? This variable is the variable.
For example:
<? Php
$ A = "go ";
$ A = "here ";
Echo $;
Echo $;
Echo $ go;
?>
The result is as follows:
Go
Here
Here
In fact, adding "$" to a variable is to use the content of this variable as a new variable name. This is unique to PHP and sometimes simplifies the program.