Php logical operators

Source: Internet
Author: User
Tags logical operators php tutorial

Php Tutorial logical operators
Example name result
$ A and $ B And (logical and) TRUE, if both $ a And $ B are TRUE.
$ A or $ B Or (logical or) TRUE, if $ a Or $ B is TRUE.
$ A xor $ B Xor (logical exclusive or) TRUE. If either $ a or $ B is TRUE, but not both.
! $ A Not (logical Not) TRUE, if $ a is Not TRUE.
$ A & $ B And (logical And) TRUE, if both $ a And $ B are TRUE.
$ A | $ B Or (logical Or) TRUE. If $ a Or $ B is set to TRUE.

<? Php
$ A = true;
$ B = false;

Echo "And (logical And)"; // TRUE, if both $ a And $ B are TRUE
Echo $ a and $ B; // return null false;

Echo "Or (logical Or)"; // TRUE, if both $ a and $ B are TRUE
Echo $ a or $ B; // returns 1 TRUE;

Echo "Xor (logical OR)"; // TRUE, if either $ a or $ B is TRUE, but not both
Echo $ a xor $ B; // returns 1 TRUE;

Echo "Not (logical Not)"; // TRUE, if $ a is Not TRUE
Echo! $ A; // return null false;

Echo "And (logical And)"; // TRUE, if both $ a And $ B are TRUE
Echo $ a & $ B; // return null false;

Echo "Or (logical Or)"; // TRUE, if $ a Or $ B is TRUE
Echo $ a | $ B; // returns 1 TRUE;
?>

<? Php

// The following foo () will not be called because they are short-circuited by the operator.
$ A = (false & foo ());
$ B = (true | foo ());
$ C = (false and foo ());
$ D = (true or foo ());

// "|" Has a higher priority than "or"
$ E = false | true; // $ e is assigned (false | true) and returns true.
$ F = false or true; // $ f is assigned to false. [Altair note: "=" has a higher priority than "or"]
Var_dump ($ e, $ f );

// "&" Has a higher priority than "and"
$ G = true & false; // $ g is assigned to (true & false) and the result is false.
$ H = true and false; // $ h is assigned true [Altair note: "=" priority is higher than "and"]
Var_dump ($ g, $ h );
?>
The output of the preceding routine is similar:

Bool (true)
Bool (false)
Bool (false)
Bool (true)

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.