How to use PHP based operators _php instance

Source: Internet
Author: User
Tags arithmetic operators logical operators

1, arithmetic operators: + 、-、 *,/,%.

2, Increment/decrement operators: such as $a++, $a--, + + $a,--$a.

Such as:

<?php
$a = 10;
$b = 5;
$c = $a + +; //First assign value, then increase. $c = $a, $a = $a +1
$d = $b--; ///First assign value, then subtract from. $d = $b, $b = $a-1
echo ' $a = '. $a. ' | | ' $c = '. $c. ' <br/> '; $a =11, $c =10
echo ' $b = '. $b. ' | | ' $d = '. $d. ' <br/> '; $b =4, $d =5
?>

<?php
$a = 10;
$b = 5;
$c =++ $a; ///increase first, then assign value. $a = $a +1, $c = $a
$d =--$b; ///Subtract first, then assign value. $b = $a-1, $d = $b
echo ' $a = '. $a. ' | | ' $c = '. $c. ' <br/> '; $a =11, $c =11
echo ' $b = '. $b. ' | | ' $d = '. $d. ' <br/> '; $b =4, $d =4
?>

3. Comparison operator: Reference document

4. Logical operators:

Such as:

$a =10; $b = 7;
if ($a ++>8 | | | $b ++>7) { //$a ++>8 is true, $b ++>7 This will not be executed.
Echo ' ok! ';
}
Echo ' a= '. $a. ' b= '. $b; //Output ok,a=11,b=7

Change

$a =10; $b = 7;
if ($a ++>10 && $b ++>7) {//$a ++>8 is false, $b ++>7 This will not be executed.
Echo ' ok! ';
}
Echo ' a= '. $a. ' b= '. $b; //A=11,b=7

Details:and && both represent logic and, where are their differences?

Mainly in the priority level above

and priority
and< = <&&
or < = < | |
such as:

$a =false | | true;//&& > = > and; Compare False First | | True, and then assign a value
$b =false or true;//| | > = > or   to assign a value $b=false first, and then compare, so the result is false
Var_dump ($a, $b);// BOOL (TRUE) bool (false)

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.