PHP syntax (2)

Source: Internet
Author: User

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.

 


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.