The PHP operator

Source: Internet
Author: User
Tags bitwise operators php operator php write

operator also called (operator)

1. Arithmetic operator +-*/% + +--

(1)% operator, two number division takes the remainder, both sides must be numeric types of data, usually used to divide the operation or control range, not for decimals or negative numbers

For example: Leap year

<? PHP     $year=2013;     if ($year$year$year%400==0) {        echo ' Leap year ';            } Else {        echo ' common year ';    }? > Leap Year and common year difference: when the whole hundred years (such as1900,300) to be divisible by 400 is a leap year, otherwise common year (2000 leap Year, 1900 common year, 300 common year), encountered during the non-whole hundred years (such as 2004,2005), A leap year is divisible by 4 and cannot be divisible by 4 to common year (2004 leap years, 2005 common year). Leap year February has 29 days, and common year's February has 28 days.

(2) after + +, the value increases after the first operation

(3) Front + +, first value increment after operation

(4) After the--, the first operation after the value minus

(5) First--, value increment and decrement operation

<?PHP$a=10; $b=$a++;//$b =10, $a =11;    $c=--$b;//$b =9, $c = 9;  $d = $c + + 10; $d =19;    $d=$c++ + ++$c;//$d =20, $c = 11;     $d =++ $c; $d =12;    $d=$d-- - --$d;//2    Echo $d;//$d =2?>

2. String operator.

<? PHP     $str 1= ' Hello ';     $str 2= ' world ';     $result=$str 1. ' ‘. $str 2 ;     Echo $str 1. ' ‘. $str 2 ;     Echo ' <br/> ';     Echo $result ;? >

Execution Result:
Hello World
Hello World

PHP Write form

<?PHP$table= ' <table border=1 width= "500px" height= "300px" > '; $table. = ' <tr><td></td><td></td><td></td><td></td></tr> '; $table. = ' <tr><td></td><td></td><td></td><td></td></tr> '; $table. = ' <tr><td></td><td></td><td></td><td></td></tr> '; $table. = ' <tr><td></td><td></td><td></td><td></td></tr> '; $table. = ' </table> '; Echo $table;?>

3. Assignment operator = + = = *=/=%=. =

<? PHP     $a=10;     // $a +=10;//$a = $a +10;    //$a-=10;//$a = $a -10;  0    //$a *=10;//$a = $a *10;    //$a/=10;//$a = $a/10;  1    //$a%=10;//$a = $a%10; 0    $a. = "abc";   $a = $a. " ABC ";  10ABC    echo$a;? >

4. Comparison operators > < >= <= = = = = = =!== <> (yes!) =

(The comparison operator has only one result, which is true or false), and the comparison operator is usually used in conjunction with the IF () conditional judgment statement, and the IF condition is true, then the statement inside is executed.

= = only compare values are equal

= = = comparison, not only to compare the content, but also to compare the type

5. Logical operators && and | | or! or not

&& and both are true, | | Or there is a true on either side of it,! It really turned out to be fake, and it turned out to be real.

6. Bitwise Operators & | ^

7. Special operators?:.. @

(1) Three mesh operator? :

Conditions? Results:

If? The preceding conditions are set up and executed? The following statement, if not true, executes: The following statement

<? PHP     $var= ' Xiaoliang ';     Echo isset ($var)? ' Yes ': ' No ';? > Execution Result: Yesisset(), determine if variable exists,falsefalse

(2) Anti-quote: Executes a system command to display the returned results

(3) @ symbol mask Error

Errors in PHP are divided into:

Notice: Prompt level, does not affect code execution

Warning: Warning level, does not affect code execution

Fatal: fatal level, affecting execution of code

(Notice and warning can be resolved by shielding errors, fatal must be debugged, resolved)

8. Operator Precedence

<? PHP     $a=10;     $b=$a++*20/(+--$a);     Echo $b ;? >
The execution result is: 10

(priority is not to see the parentheses on the execution, but to meet the parentheses, the execution of the parentheses inside the operation, and then participate in the outside operation)

The PHP operator

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.