亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP operators

In PHP, the assignment operator = is used to assign values ??to variables.

In PHP, the arithmetic operator + is used to add values ??together.

PHP Arithmetic Operator

Symbol Description ? ? ? ? ? ? ? ? ? ? ? Example

+ ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? $x +?????????????????????????????????????Multiplication sign, multiply by $x * $y
/ ? ? ? ? Division sign, divided by ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Different results obtained by arithmetic operators:

Example

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

Try it ?

PHP7+ version has a new integer division operator intdiv(), learn about it here. Usage example:

<?php 
var_dump(intdiv(10, 3)); 
?>

The above example will output:

int(3)

PHP assignment operator

in PHP , the basic assignment operator is "=". It means that the left operand is set to the value of the right-hand expression. That is, the value of "$x = 5" is 5.

Symbol ? ? ? ? ? ?

Example ? ? ? ? ? ?

Equivalent equation

#= ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Is set to the value of the expression on the right

##+= ? ? ? ? ? $x += ?$y ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?y $x = $x - $y *= $y / $y %= $x %= $y $x = $x % $y

.= $y $x .=$y $x = $x . $y

The following examples demonstrate different results obtained by using different assignment operators:
Examples

<?php 
$x = 10; 
echo $x; // 輸出10
$y = 20; 
$y += 100;
echo $y; // 輸出120
$z = 50;
$z -= 25;
echo $z; // 輸出25
$i = 5;
$i *= 6;
echo $i; // 輸出30
$j = 10;
$j /= 5;
echo $j; // 輸出2
$k = 15;
$k %= 4;
echo $k; // 輸出3
?>

Try it out?

The following examples demonstrate different results obtained by using different string operators:

Example

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

Try it ?

PHP Increment/Decrease Operator

Operator????????????????????????????????????????????????????????????????????????????????????????????????????1, then return x -later decreased back X, and then x minus 1 The following example demonstrates the results obtained by the use/decreased transport calculation symbol: ## r Check it out?

PHP Comparison Operators

Comparison operators allow you to compare two values:

Operators

##Name ?????????????????????????????????????????????????????????????????????????????????????????????????????????????

#x =8 returns false

##x === y is always equal to y If x is equal to y and they are of the same type, return true #X! = Y is not equal to if X is not equal to Y, then return True 5! = 8 Return True

x <> y is not equal to y If x is not equal to y, return true ! == y is not equal to y if x is not equal to y, or their types If they are not the same, return true 5!=="5" Return true

##x > y is greater than y? ? ? ? ? ? ? ? ? 5>8 returns false

x < y ? ? ? ? ? ? ? ? ? ? ? is less If x is less than y, return True 5 & LT; 8 Return True

# x & GT; = y greater or equal to if x is greater than or equal to Y, then return True 5 & GT; ;= y less than or equal to y If x is less than or equal to y, return true #
<?php
$x = 10; 
echo ++$x; // 輸出11  
$y = 10; 
echo $y++; // 輸出10  
$z = 5;
echo --$z; // 輸出4  
$i = 5;
echo $i--; // 輸出5
?>

Try it?

PHP Logical Operator

##Operator ? ? ? ? ?

Name ? ? ? ? ? ?

Description ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ?

Example

x and y Logical AND ? ? ? ? ? ? If both x and y are true, then return true ? ? ? ? ? ? ? ? ? ? ?) Return true x or y Logical OR If at least one of x and y is true, return true x=6 y=3 (x==6 or y==5) Return true x xor y Logical XOR If one and only one of x and y is true, then return true x=6 y=3 (x==6 xor y==3) Return false

x && y Logical AND If both x and y are true, return true x=6 y=3 (x < 10 && y > 1) Return true

##x || y Logical OR If x If at least one of y and y is true, then return true x=6 y=3 !(x==y) Returns true

Here are a few examples:

Logic and

<?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);
?>

Logic or

<?php 
$x = true; 
$y = false; 
//邏輯與(并且),要求兩個(gè)都為true才執(zhí)行真區(qū)間,所以代碼中執(zhí)行假區(qū)間 
if($x && $y){ 
echo '執(zhí)行了真區(qū)間'; 
}else{ 
echo '執(zhí)行了假區(qū)間'; 
} 
?>

logical NOT

<?php 
$x = true; 
$y = false; 
//邏輯或,有一個(gè)為真則為真 
if($x || $y){ 
echo '執(zhí)行了真區(qū)間'; 
}else{ 
echo '執(zhí)行了假區(qū)間'; 
} 
?>

PHP Array Operator

Operator ? ? ? ? ? ?

Name ? ? ? ? ? ? ? Description

x + y ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ?#x === y ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ’ ’ s ’ s ’ s ’ s ’s ’ s ’ s ‐ ‐ ‐ ‐ ‐ to be true if x and y have the same key/value pairs in the same order and the same type Returns true

x <> y is not equal If x is not equal to y, then return true

x !== y Not equal If x is not equal to y, then return true

The following Examples demonstrate different results using some array operators:

Example

<?php 
$y = false; 
//邏輯非,把false變?yōu)榱藅rue 
if(!$y){ 
echo '執(zhí)行了真區(qū)間'; 
}else{ 
echo '執(zhí)行了假區(qū)間'; 
} 
?>

Try it out?

Ternary Operator

Another conditional operator is the "?:" (or ternary) operator.

Syntax format

(expr1) ? (expr2) : (expr3)

When expr1 evaluates to TRUE, the value is expr2. The value of expr1 when evaluating to FALSE is expr3.

can be written as: $x? True code segment (only one line of code can be written): Fake code segment (only one line of code can be written);

Since PHP 5.3, the ternary can be omitted The middle part of the operator. The expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE and expr3 otherwise.

Example

In the following example, it is judged that the $_GET request contains the user value. If so, $_GET['user'] is returned, otherwise nobody is returned:

$_GET variable Will be explained in the PHP form with reference to PHP $_GET variable

<?php
$x = array("a" => "red", "b" => "green"); 
$y = array("c" => "blue", "d" => "yellow"); 
$z = $x + $y; // $x 和 $y 數(shù)組合并
var_dump($z);
var_dump($x == $y);
var_dump($x === $y);
var_dump($x != $y);
var_dump($x <> $y);
var_dump($x !== $y);
?>

Note: PHP_EOL is a newline character and is compatible with larger platforms.

There is an additional NULL merge operator in the PHP7+ version. The example is as follows:

<?php 
$test = 'php中文網(wǎng)'; 

//普通寫法 
$username = isset($test) ? $test : 'nobody'; 
echo $username, PHP_EOL; //輸出 php中文網(wǎng)

// PHP 5.3+ 版本寫法 
$username = $test ?: 'nobody'; 
echo $username, PHP_EOL; //輸出 php中文網(wǎng)
?>

Combined comparison operator (PHP7+)

PHP7+ supports combined comparison operator. The example is as follows:

<?php 
// 如果 $_GET['user'] 不存在返回 'nobody',否則返回 $_GET['user'] 的值 
$username = $_GET['user'] ?? 'nobody'; 
// 類似的三元運(yùn)算符 
$username = isset($_GET['user']) ? $_GET['user'] : 'nobody'; 
?>

Operator precedence

Operator precedence is a very complex rule, please refer to http://php.net/manual/zh/language.operators.precedence.php No need Memorize by rote,

We only need to understand the commonly used rules, from high to bottom:

++, -- (increasing and decreasing)

! Logical NOT

Multiplication and division operations are higher than addition and subtraction operations (multiplication and division first, then addition and subtraction)

Comparison operators (calculate first and then compare)

Logical operators (results of comparison Do logical operations)


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