Home  >  Article  >  Backend Development  >  Collection of php operators

Collection of php operators

小云云
小云云Original
2018-03-01 10:18:111590browse

Everyone will come into contact with operators when learning programming languages. This article mainly shares with you a collection of PHP operators, hoping to help everyone.

1. Operator precedence
Increment/Decrease> ! > Arithmetic operators> Size comparison> (Not)Equality comparison> Reference>
Bit operator (^ ) > bit operator (|) > logical AND > logical OR > ternary > assignment > and > Use

2. Comparison operators
2.1, the difference between == and ===
==: Comparison value
===: Comparison value and comparison type

2.2. Judgment of equality (seven cases of FALSE)
0, 0.0, ' ', '0', false, array(), null

2.3. Increasing and decrementing does not affect the Boolean value

2.4. Decreasing the NULL value has no effect, but increasing the NULL value is 1

3. Logical operators
3.1. Short-circuit effect
$a = true || $b == 3 ;//$b is not executed
$b = false && $a == 1;//$a is not executed

3.2, || and && have different priorities from or and and
&& > || > and > or

$a = false || true; //true
$b = false or true; // false



4. Example

<?php

/**
 * 下列程序中请写出打印输出的结果
 * <?php
 *
 * $a = 0;
 * $b = 0;
 *
 * if ($a = 3 > 0 || $b = 3 > 0) 
 * {
 *      $a++;
 *      $b++;
 *      echo $a. "\n";
 *      echo $b. "\n";
 * }
 */
$a = 0;
$b = 0;

if ($a = 3 > 0 || $b = 3 > 0) 
{
/**
*	> 的优先级大于 || 大于 =
*	因此可以认为是
*	$a = ((3 > 0) || $b = 3 > 0)
*	=> $a = (true || $b = 3 > 0)
*	由于逻辑或短路作用,b 不再执行
*	因此:$a = true, b = 0
*	由于布尔值递增和递减都不影响还是true,而打印echo时,true底层转为1
*	因此最终echo a 和 b,都是1
*/
    $a++;
    $b++;
    echo $a. "\n";
    echo $b. "\n";
}

Related recommendations:


Simple questions about PHP operator priority

##PHP Examples of operators

Detailed explanation of php operators and expression usage examples

The above is the detailed content of Collection of php operators. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn