• 技术文章 >php教程 >php手册

    PHP3中文文档(续5)

    2016-06-21 09:10:31原创437

    中文

    算术操作符

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

     

    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.




    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:nbsp FONT True gt quot
    上一篇:PHP中重新定向到另一个页面 下一篇:用PHP处理多个同名复选框
    VIP课程(WEB全栈开发)

    相关文章推荐

    • 【腾讯云】年中优惠,「专享618元」优惠券!• PHP跳转页面的三种方式• php 生成静态html• PHP弥补Ajax在浏览器导航上的不足• PHP中$_SERVER的详细参数及说明• 解析如何通过PHP函数获取当前运行的环境 来进行判断执行逻辑(小技巧)
    1/1

    PHP中文网