首页 > 开发 > PHP > 正文

PHP3中文文档(续5)

2024-05-04 22:56:49
字体:
来源:转载
供稿:网友
算术操作符

    这些工作和基本的学校里教的内容相似。

 

    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 < $b less than?/font>   true if $a is strictly less than $b.?/font>
$a > $b greater than?/font>   true if $a is strictly greater than $b.?/font>
$a <= $b less than or equal to?/font>  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.



发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表