Home  >  Article  >  Backend Development  >  Summary of operators in php

Summary of operators in php

PHP中文网
PHP中文网Original
2017-10-31 09:36:362708browse

<?php
/*  PHP的运算符号
 *    
 *    运算元   运算符   运算元
 *
 *     1         +      1 
 *  
 *    一元运算符  +1  -1  ++  --   ! 
 *
 *    二元运算符   +  - *  /  %   > < =  ==  ===  
 *
 *    三元运算符  1 ? 2 : 3
 *
 *   $a = 10;
 *
 *    算术运算符号  + - * / % ++ --
 *    赋值运算符号  = += -= *= /= %=
 *    比较运算符号  > < == >= <= === != !== 
 *    逻辑运算符号  && || ! 
 *    位运算符号    &  | ^  ~  >> << 
 *
 *    其它运算符号   ? :   @    => -> 
 *
 */
 ?>

•An operator is something that takes one or more given values ​​(an expression, in programming jargon) and produces another value (thus the entire structure becomes an expression). So think of functions or any structure that returns a value (like print) as operators, and those that don't return a value (like echo) as something else.

•There are three types of operators:

– Unary operators that operate on only one value, such as ! (the negation operator) or ++ (the addition operator).

– Binary operator, with two operands, most operators supported by PHP are of this type.

–Ternary operator: ? :.

It should be used to choose one expression between two other expressions, not to choose between two statements or program routes. It's a good idea to enclose the entire ternary expression in an expansion sign.

Operators in PHP

1. Arithmetic operators

## Common arithmetic operations Symbol

Operation typeOperatorExampleResultInversion operation--$aReturn the negative value of $aAddition operation+$a + $bReturns the sum of $a and $bSubtraction operation-$a - $bReturn $a and $ Difference of bMultiplication operation*$a * $b##Division operationRemainder operation
##Returns the product of $a and $b
/ $a / $b Returns the quotient of $a and $b
% ##$a % $b Return the remainder of $a and $b

2. Logical operators

Logical operators in PHP

##Operation typeOperatorExampleResultLogical and&& or and$a && $b or $a and $bWhen both $a and $b are true, return true, otherwise return falseLogical or|| or or$a || $b or $a or $bWhen $a or $b is When true, return true, otherwise return falseLogical XORxor$a xor $bWhen $a is true, $b is false or $a is false, $b is true, return true, otherwise return falselogical negation!
##!$a When $a is false, return true, otherwise return false
3. Assignment operator

The assignment operator "=" is the most basic operator in PHP, which assigns the value of the expression on the right side of "=" to the operand on the left.

In addition, the compound assignment operator is also commonly used in PHP.

                                                                     

Operator

Example##$a += 5Subtractive assignment-=$a -= 5Multiplication assignment*=$a *= 5Division assignment/=$a /= 5The remainder is assigned% =$a %= 5
Result Addition assignment +=
$a adds 5 and assigns the sum to $a
$a minus 5 is assigned to $a
The product of $a times 5 is assigned to $a
The quotient of $a divided by 5 is assigned to $a
# The remainder of $a divided by 5 is assigned to $a

4. Comparison operators

##is less than040897171c6303a7dfeaaa07230d7d17$a > $bwhen $a If the value is greater than the value of $b, it returns true, otherwise it returns false is less than or equal to 1798a003a606b970d231704318bd41bf=$a >= $bWhen the value of $a is greater than or equal to the value of $b, return true, otherwise return false##EqualCongruentNot equal Not equal
Operation type Operator Example Result
== $a == $b When the value of $a is equal to the value of $b, it returns true, otherwise it returns false
=== $a === $b When the value of $a is equal to the value of $b, and the value of $a and $b If the types are also equal, return true, otherwise return false
!= $a != $b or $a 6d267e5fab17ea8bc578f9e7e5e1570b $b When the value of $a is equal to the value of $b, it returns false, otherwise it returns true
!== $a !== $b When the value of $a is equal to the value of $b, and the types of $a and $b are also equal, return false, otherwise return true

The above is the detailed content of Summary of operators in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn