PHP operator for front-end learning

Source: Internet
Author: User
Tags php operator

Directory arithmetic operator assignment operator comparison operator ternary operator logical operator string operator error control operator increment decrement operator array operator definition

the operator is the identification symbol for the operation. PHP operators are generally divided into arithmetic operators, assignment operators, comparison operators, ternary operators, logical operators, string join operators, error control operators , increment decrement operators, and array operators

Arithmetic operators
+(addition)    $x$y-(subtraction)    $x$y*(multiplication)    $x  $y/(division)    $x$y%(modulo    )$x$y 

Assignment operators

There are two types of assignment operators for PHP, namely direct assignment "=" and Reference assignment "&"

[1] Direct Assignment

Direct Assignment "=" assigns the value of the right expression to the left operand. It copies the value of the right expression to the left-hand operand. In other words, first apply a piece of memory to the left operand, and then put the copied value in this memory

x =+==*=/=%= y

[2] Reference assignment

Reference assignment & means that both variables point to the same data. It will allow two variables to share a piece of memory, and if the data stored in this memory changes, then the values of the two variables will vary.

<? PHP      $a = "Test content 1";     $b $a ;     $c = &$a;     $a = "Test content 2";     Echo $b. " <br/> "; // Test content 1    Echo $c. " <br/> "; // Test Content 2?>

Comparison operators

Comparison operators are primarily used for comparison operations

=         = = =         congruent = =          unequal <> unequal!==         not          equal to >           Greater than <           less than >=          greater than or equal to <=         less than equals
<?PHP$a= 1; $b= "1"; Var_dump($a==$b); Echo"<br/>";//bool (TRUE)    Var_dump($a===$b); Echo"<br/>";//bool (FALSE)    Var_dump($a!=$b); Echo"<br/>";//bool (FALSE)    Var_dump($a<>$b); Echo"<br/>";//bool (FALSE)    Var_dump($a!==$b); Echo"<br/>";//bool (TRUE)    Var_dump($a<$b); Echo"<br/>";//bool (FALSE)?>

Ternary operators

"?:" The ternary operator is a comparison operator, for an expression (EXPR1)? (EXPR2):(EXPR3), if the value of EXPR1 is true, the value of this expression is expr2, otherwise EXPR3

<? PHP      $a = 78; // Achievements    $b $a >=60? " Pass ":" Failed ";     Echo $b; // passing ?>

logical operators

Logical operators are primarily logical operations

and        with or         or xor         && | |                    or !          Non -
<?PHP$a=TRUE;//a agree    $b=TRUE;//B Agree    $c=FALSE;//C Objection    $d=FALSE;//D against    Echo($aand$b);//1    Echo"<br/>"; Echo($aOr$c);//1    Echo"<br/>"; Echo($aXor$cXor$d);//1    Echo"<br/>"; Echo(!$c? "Pass": "does not pass");//through    Echo"<br/>"; Echo($a&&$d? "Pass": "does not pass");//does not pass    Echo"<br/>"; Echo($b||$c||$d? "Pass": "does not pass");//through?>

String operators

The string join operator is to concatenate two strings

[1] connection operator (.)

<? PHP      $a = ' Hello ';     $b $a . ' world! ' ;     // Hello world!    Echo $b ;? >

[2] Connection assignment operator (. =)

<? PHP      $x = ' Hello ';     $x . = ' world! ' ;     // Hello world!    Echo $x ;? >

Error control operator

PHP provides an error control operator @, for some expressions that may have errors in the run, and you do not want to display an error message when the fault occurs, put @ before a PHP expression. If the Track_error attribute is activated, any error information generated by the expression is stored in the variable $php_errormsg, which will be overwritten every time an error occurs.

[note] The error control prefix @ does not mask parsing error information, it cannot be placed before the definition of a function or class, nor can it be used for conditional structures such as if and foreach

<? PHP $a = 1; Echo $a; // 1 $b ; Echo $b; // No error ?>

Increment/decrement operator
+ +$x      before increment $x+ +      increment - -      decrement before $x $x--     decrement after
<?PHP$x=10; Echo++$x;//output one by one$y=10; Echo $y++;//Output Ten$z=5;Echo--$z;//Output 4$i=5;Echo $i--;//Output 5?>

Array operators

Used to compare arrays

+       union = =      equal = = = Congruent !       =      unequal <> unequal!== Not congruent
<?PHP$x=Array("A" and "Red", "b" = "green")); $y=Array("c" = "Blue", "d" = "Yellow"); $z=$x+$y; Var_dump($z);//Array (4) {["a"]=> string (3) "Red" ["B"]=> string (5) "Green" ["C"]=> string (4) "Blue" ["D"]=> string (6) " Yellow "}Echo"<br>";Var_dump($x==$y);//bool (FALSE)Echo"<br>";Var_dump($x===$y);//bool (FALSE)Echo"<br>";Var_dump($x!=$y);//bool (TRUE)Echo"<br>";Var_dump($x<>$y);//bool (TRUE)Echo"<br>";Var_dump($x!==$y);//bool (TRUE)?>

PHP operator for front-end learning

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.