A brief discussion of PHP syntax (2)_PHP tutorial

WBOY
Release: 2016-07-13 17:20:54
Original
935 people have browsed it

The previous article only talked about the data types of PHP. The so-called "sharpening the knife does not waste time cutting firewood". Only by laying a good foundation in PHP can you learn PHP programming better.
  PHP中的表达式与运算符与C语言的差别不大,现将其列表于下:
┌─────┬─────────┬──────────┐
│ 符 号 │ 运算符 │ 范 例 │
├─────┼─────────┼──────────┤
│ + │ 加法 │ $a+$b │
├─────┼─────────┼──────────┤
│ - │ 减法 │ $a-$b │
├─────┼─────────┼──────────┤
│ * │ 乘法 │ $a*$b │
├─────┼─────────┼──────────┤
│ / │ 除法 │ $a/$b │
├─────┼─────────┼──────────┤
│ % │ 取余数 │ $a%$b │
├─────┼─────────┼──────────┤
│ ++ │ 递增 │ $a++或++$a │
├─────┼─────────┼──────────┤
│ -- │ 递减 │ $a--或--$a │
├─────┼─────────┼──────────┤
│ == │ 等于 │ $a==10 │
├─────┼─────────┼──────────┤
│ === │ 绝等于 │ $a===10 │
├─────┼─────────┼──────────┤
│ != │ 不等于 │ $a!=10 │
├─────┼─────────┼──────────┤
│ < │ 小于 │ $a<9 │
├─────┼─────────┼──────────┤
│ > │ 大于 │ $a>8 │
├─────┼─────────┼──────────┤
│ <= │ 小于等于 │ $a<=10 │
├─────┼─────────┼──────────┤
│ >= │ 大于等于 │ $a>=1 │
├─────┼─────────┼──────────┤
│ = │ 相等赋值运算符 │ $a=0 │
├─────┼─────────┼──────────┤
│ += │ 加法指定运算符 │ $a+=5 │
├─────┼─────────┼──────────┤
│ -= │ 减法指定运算符 │ $a-=1 │
├─────┼─────────┼──────────┤
│ *= │ 乘法指定运算符 │ $a*=2 │
├─────┼─────────┼──────────┤
│ /= │ 除法指定运算符 │ $a/=5 │
├─────┼─────────┼──────────┤
│ %= │ 余数指定运算符 │ $a%=7 │
├─────┼─────────┼──────────┤
│ .= │ 字符串指定运算符│ $a.="hello" │
├─────┼─────────┼──────────┤
│ & │ 与 │ $a&$b │
├─────┼─────────┼──────────┤
│ | │ 或 │ $a|$b │
├─────┼─────────┼──────────┤
│ ^ │ Xor │ $a^$b │
├─────┼─────────┼──────────┤
│ ~ │ 非 │~$a(取1的补码 )│
├─────┼─────────┼──────────┤
│ << │ 向左移位 │ $a<<$b │
├─────┼─────────┼──────────┤
│ >> │ 向右移位 │ $a>>$b │
├─────┼─────────┼──────────┤
│and或&& │ 与 │$a and $b或$a&&$b │
├─────┼─────────┼──────────┤
│or或|| │ 或 │$a or $b或$a||$b │
├─────┼─────────┼──────────┤
│xor │ Xor │ $a xor $b │
├─────┼─────────┼──────────┤
│ ! │ 非 │ !$a │
└─────┴─────────┴──────────┘
┌───┬────────────┐
│符号 │ 意义说明 │
├───┼────────────┤
│ $ │变量 │
├───┼────────────┤
│ & │变量的指针(加在变量前)│
├───┼────────────┤
│-> │对象的方法或属性 │
├───┼────────────┤
│=> │Element value of array│
├───┼───────────┤
│? : │Ternary operator│
└─── ┴─────────────┘
Let’s compare it with C language. There is just one more "." operator. Its function is to connect two strings, as in the following example, the displayed result is hello, my baby.
$a="hello,";
$b="my baby. ";
echo $a.$b;
?>
There is another symbol that also makes PHP powerful. This is "$". It is used before a variable, indicating that this is a variable, such as $A, $b, etc. So what is its powerful function? This is the variable of variables.
Example:
$a="go";
$$a="here";
echo $a;
echo $$a;
echo $go;
?>
The displayed result is:
go
here
here
In fact, adding a "$" before a variable means that the variable The content is used as a new variable name. This is unique to PHP and can sometimes simplify the program.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532533.htmlTechArticleThe previous article only talked about the data types of PHP. The so-called "sharpening the knife without chopping firewood" lays a good foundation for PHP. Only in this way can you learn PHP programming better. The expressions and operators in PHP are not much different from those in C language,...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template