Php array operator (+), string operator (.), logical operator (& AND | ORXO

Source: Internet
Author: User
Array operator (+), string operator (.), logical operators (amp; AND | ORXOR) have a need for friends can refer to the reference. php array operator $ a + $ B Union $ a and $ B Union. nbs... array operator (+), string operator (.) AND logical operators (& AND | or xor). For more information, see.

Php array operators

$ A + $ B join $ a and $ B.

$ A = $ B is equal. if $ a and $ B have the same key/value pair, the value is TRUE.

$ A ===$ B. TRUE if $ a and $ B have the same key/value pairs and the order and type are the same.

$! = $ B. If $ a is not equal to $ B, it is TRUE.

$ A <> $ B: TRUE if $ a is not equal to $ B.

$! = $ B incomplete. if $ a is not all equal to $ B, TRUE is returned.

The only array operator in PHP is the + operator. it attaches the array on the right to the array on the left, but duplicate key values are not overwritten.

The instance code is as follows:

$a = array("a" => "apple", "b" => "banana"); $b = array("a" =>"pear", "b" => "strawberry", "c" => "cherry"); $c = $a + $b; var_dump($c);

After the script is executed, the script displays:

The instance code is as follows:

array(3) {   ["a"]=>   string(5) "apple"   ["b"]=>   string(6) "banana"   ["c"]=>   string(6) "cherry" }

If the elements in the array have the same key name and value, the comparison is equal.

Example #1 compare arrays

The instance code is as follows:

  "banana", "0" => "apple");     var_dump($a == $b); // bool(true)     var_dump($a === $b); // bool(false) ?>

String operators

There are two string operators. the first is the concatenation operator (". ), it returns the string after the left and right parameters are connected. the second is the join value assignment operator (". = "), it attaches the parameter on the right to the parameter on the left

The instance code is as follows:

 

The instance code is as follows:

 

Logical operators

Example of logical operators in the following table

$ 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 TRUE.

"And" and "or" have two different operators because they have different operation priorities.

The instance code is as follows:

 

The instance code is as follows:

 

The output of the preceding routine is similar:

bool(true)bool(false)bool(false)bool(true)
Related Article

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.