dongmangzong8006 2014-04-01 17:50
浏览 33
已采纳

学习PHP,布尔代数

So i've just started learning PHP and i came across a part i didn't quite understand.

The book gave me three lines.

&& and true && true=true, every other combination results in false.

|| or false || false=false, every other combination results in true.

XOR or false XOR true=true, every other combination results in false.

If anyone can clarify what this means i would very much appreciate it.

Edit

the following is text above my previous part.

Every equation yields a value: either true(1) or false(0).

echo true + true + false

This results in a value of 2 (1 + 1 + 0).

  • 写回答

2条回答 默认 最新

  • dtwxmn8741 2014-04-01 17:55
    关注

    There are three boolean operators mentioned there: && (logical AND), || (logical OR), and XOR (well, it's logical XOR, or 'exclusive OR'). All of these are binary ones - they take two operands. Its result, apparently, is a boolean value - either true or false.

    Now, they function as follows:

    • && will only result in true if both its operands evaluate to true, otherwise the result will be false
    • || will only result in false if both its operands evaluate to false, otherwise the result will be true
    • XOR will result in false if its operands evaluate to the same value - be it true or false, doesn't matter. But if one operand evaluates to false, and another to true, the result is true.

    Now, on the second part of your question: this...

    echo true + true + false;
    

    ... doesn't have anything to do with boolean algebra. All the operands of + are cast to the numeric type first, by the rules described in Type Juggling section of the PHP documentation. In short, true is converted to 1, false to 0; the result - 1 + 1 + 0, or 2, is printed out.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)