国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP operators

PHP Arithmetic Operator

## + - *
## Operator Name Example Result
Addition$x + $ySum of $x and $y
Subtraction$ x - $yThe difference between $x and $y
Multiplication$x * $yThe product of $x and $y
/ Division$x / $yQuotient of $x and $y
% Remainder is also called modulus and modulus$x % $y$x is the remainder after dividing $y

Example

The following example shows different results using different arithmetic operators:

<?php
 $x=10;
 $y=6;
 echo ($x + $y)."<br/>"; // 輸出 16
 echo ($x - $y)."<br/>"; // 輸出 4
 echo ($x * $y)."<br/>"; // 輸出 60
 echo ($x / $y)."<br/>"; // 輸出 1.6666666666667
 echo ($x % $y)."<br/>"; // 輸出 4
 ?>

PHP assignment operator

In mathematics, we call = (an equal sign) the assignment operator, that is: assign the value on the right side of the equal sign. If the variable on the left side of the equal sign is given, the variable on the left side will be the value on the right side.

Symbol Example Equivalent equation
+=$x += $y $x = $x + $y
-=$x -= $y$x = $x - $y
*=$x *=$y#$x = $x * $y
??/=$x /= $y$x = $x / $y
?%=$x %= $y$x = $x % $y
? ? .$x .= $y#$x ?= $x . $y

Examples

The following examples and equivalent equations are clearly explained.

$x += $y is equivalent to $x = $x + $y

<?php
 $x = 5;
 $y = 8;
 $x += $y;
 echo $x;

PHP characters String operator

## Concatenation$txt1 = "Hello" $txt2 = $txt1 . " world!" Now $txt2 contains "Hello world!" Concatenation assignment $txt1 = "Hello" $txt1 .= " world!"Now $txt1 contains "Hello world!"

Example

The following example shows the result of using string operators:

<?php
 $a = "Hello";
 $b = $a . " world!";
 echo $b; // 輸出 Hello world!
 echo "<br/>";
 $x="Hello";
 $x .= " world!";
 echo $x; // 輸出 Hello world!
 ?>

PHP increment/decrement operator

Increment and decrement are simply to add one to yourself Or minus one

Operator Name Example Result
.
.=
Symbol Description
$x++ Assign first and then add
$x-- Assign first and then subtract
++$x Add first and then assign value
--$x Subtract first and then assign value

The above usage is actually quite simple, follow the above example. We divide it into steps and judge according to the process.

Example

<?php
 $x = 5;
 //先賦值后加:即先將$x的值賦值給$y。$x的值為5,所以將$x的值賦值給$y。$y也為5
 $y = $x++;
 //$x的結(jié)果輸出為6,因為賦值給$y后,$x自己又把自己進行了+1操作。所以,$x的結(jié)果為6
 echo $x;
 ?>

Let’s compare adding first and then assigning, as follows:

<?php
 $x = 8;
 $y = ++$x;
 echo $x;
 ?>

You can do another experiment and try $x-- and--$x


## Small test

See if you can guess the result of $water + $paper below?

<?php
 $x = 5;
 $y = 6;
 $paper = ++$x + $x++;  
 $water = $y-- + $x--;  
 echo $water + $paper;
 ?>

Did you guess it right

# #PHP comparison operators:

PHP comparison operators are used to compare two values ??(numbers or strings):

## == Equal to $x == $y Returns true if $x is equal to $y. If $x is equal to $y and they are of the same type, return true != is not equal to $x != $yReturns true if $x is not equal to $y.
Operator Name Example Result
===
Congruent (identical)
$x === $y
<> Not equal to$x <> $yIf $x is not equal to $ y, returns true.

!==

Not congruent (completely different)

$x !== $y
If $x is not equal to $y, and they are not the same type, return true.
> is greater than $x > $yReturns true if $x is greater than $y.
< is less than $x < $yReturns true if $x is less than $y.
>= Greater than or equal to$x >= $yIf $x is greater than or equal to $ y, then return true.
<= is less than or equal to$x <= $y Returns true if $x is less than or equal to $y.

Example

The following example shows different results using certain comparison operators:

<?php
 $x=100;
 $y="100";
 var_dump($x == $y);
 echo "<br>";
 var_dump($x === $y);
 echo "<br>";
 var_dump($x != $y);
 echo "<br>";
 var_dump($x !== $y);
 echo "<br>";
 
 $a=50;
 $b=90;
 
 var_dump($a > $b);
 echo "<br>";
 var_dump($a < $b);
 ?>

##PHP Logical Operator



and and$x and $yIf $x and $y are both true, return true. ## or or$x or $y## xor

Operator Name Example Result



if $x and If at least one of $y is true, return true.

XOR

$x xor $y
if $x If only one of $y and $y is true, then true is returned.
## && and$x && $yIf If both $x and $y are true, return true. ! Not!$xIf $x is not true, returns true.

Let’s give a few examples to try,

Logical AND:

<?php
 header("Content-type:text/html;charset=utf-8");    //設(shè)置編碼
 $x = true;
 $y = false;
 //邏輯與(并且),要求兩個都為true才執(zhí)行真區(qū)間,所以代碼中執(zhí)行假區(qū)間
 if($x && $y){
     echo '執(zhí)行了真區(qū)間';
 }else{
     echo '執(zhí)行了假區(qū)間';
 }
 ?>

Logical OR:

<?php
 header("Content-type:text/html;charset=utf-8");    //設(shè)置編碼
 $foo = false;
 $bar = true;
 //邏輯或,有一個為真則為真
 if($foo || $bar){
     echo '執(zhí)行真區(qū)間';
 }else{
     echo '執(zhí)行假區(qū)間';
 }
 
 ?>

Logical NOT:

<?php
 header("Content-type:text/html;charset=utf-8");    //設(shè)置編碼
 $foo = false;
 //邏輯非,把false變?yōu)榱藅rue
 if(!$foo){
     echo '執(zhí)行真區(qū)間';
 }else{
     echo '執(zhí)行假區(qū)間';
 }
 
 ?>

PHP array operator


## ||

## or

$x || $y

Returns true if at least one of $x and $y is true.

## + == Equal$x == $y## ===
## Operator Name Example Result
Union$x + $y Union of $x and $y (but not Overwrite duplicate keys)



Returns true if $x and $y have the same key/value pair.

Congruent

$x === $y
If $x and $y have the same key/value pairs in the same order and type, return true.
!= Not equal$x != $yIf $x is not equal to $y, return true.
<>Not equal$x <> $yIf $x is not equal to $ y, returns true.
!==Not congruent$x !== $yIf $x is completely different from $y , then returns true.

PHP array operators are used to compare arrays:

Example

The following example shows different results using different array operators:

<?php
 $x = array("a" => "red", "b" => "green");
 $y = array("c" => "blue", "d" => "yellow");
 $z = $x + $y; // $x 與 $y 的聯(lián)合
 var_dump($z);
 var_dump($x == $y);
 var_dump($x === $y);
 var_dump($x != $y);
 var_dump($x <> $y);
 var_dump($x !== $y);
 ?>

Ternary operator


##Ternary operator format:

##(expr1)?(expr2):(expr3); //Expression1?Expression2:Expression3

Example

<?PHP
 $a=10; $b=20;
 $c=$a>$b?($a-$b):($a+$b);
 //說明:如果變量a大于變量b則執(zhí)行問號后面的,否則就執(zhí)行:冒號后面的
 echo $c;
 ?>


Continuing Learning
||
<?php $x=10; $y=6; echo ($x + $y)."<br/>"; // 輸出 16 echo ($x - $y)."<br/>"; // 輸出 4 echo ($x * $y)."<br/>"; // 輸出 60 echo ($x / $y)."<br/>"; // 輸出 1.6666666666667 echo ($x % $y)."<br/>"; // 輸出 4 ?>
submitReset Code