中文
算术操作符
这些工作和基本的学校里教的内容相似。
Table 7-1. Arithmetic Operators(表7-1算术操作符)
example name result
$a + $b Addition Sum of $a and $b.?/FONT>
$a - $b Subtraction Remainder of $b subtracted from $a.?/FONT>
$a * $b Multiplication Product of $a and $b.?/FONT>
$a / $b Division Dividend of $a and $b.?/FONT>
$a % $b Modulus Remainder of $a divided by $b.
其中,除法操作符“/”返回一个整数值(整数除法的结果)如果两个操作数是整数(或者是被转化成整数的字符串)的话。如果任意一个操作数是浮点数,那么将进行浮点运算。
字符串操作符
这个地方仅仅有一个真正的字符串操作符:串联符号“.”。
$a = "Hello ";$b = $a . "World!";
// now $b = "Hello World!"
赋值操作符
基本的赋值操作符就是“=”。您往往会倾向于认为它的含义就是“等于”。不要这样想,它真正的含义就是左侧的操作数获得右侧表达式的值。
一个赋值表达式的意义在于值的指派。也就是说,“$a=3”的值是3。这就允许您做这样的事情:
$a = ($b = 4) + 5;
// $a is equal to 9 now, and $b has been set to 4.
作为赋值操作符的一个补充,还有一个针对二进制数和字符传进行操作的组合操作符,该操作符允许您在赋值方采用被赋值表达式的值。例如:
$a = 3;
$a += 5; // sets $a to 8, as if we had said: $a = $a + 5;
$b = "Hello ";
$b .= "There!"; // sets $b to "Hello There!", just like $b = $b . "There!";
位操作符
位操作符允许您精细的操作数据的每一个位。
Table 7-2. Bitwise Operators(表7-2位操作符)
example name result
$a & $b And Bits that are set in both $a and $b are set.?/FONT>
$a | $b Or Bits that are set in either $a or $b are set.?/FONT>
~ $a?/FONT> Not Bits that are set in $a are not set, and vice versa.
逻辑操作符
Table 7-3. Logical Operators(表7-3 逻辑操作符)
example name result?/FONT>
$a and $b And True of both $a and $b are true.?/FONT>
$a or $b Or?/FONT> True if either $a or $b is true.?/FONT>
$a xor $b Or?/FONT> True if either $a or $b is true, but not both.?/FONT>
! $a Not?/FONT> True if $a is not true.?/FONT>
$a && $b And?/FONT> True of both $a and $b are true.?/FONT>
$a || $b Or?/FONT> True if either $a or $b is true.
比较操作符
比较操作符,正如它的名字所示,允许您比较两个值。
Table 7-4. Comparson Operators(表7-4 比较操作符)
example name result?/FONT>
$a == $b Equal?/FONT> True if $a is equal to $b.?/FONT>
$a != $b Not equal True if $a is not equal to $b.?/FONT>
$a True if $a is strictly less than $b.?/FONT>
$a > $b Greater than?/FONT> True if $a is strictly greater than $b.?/FONT>
$a True if $a is less than or equal to $b.?/FONT>
$a >= $b Greater than or equal to?/FONT> True if $a is greater than or equal to $b.