Comparison operator == (the equality operator) and === (operator identity) for comparing two values. They are also known loosely equal (==) and exactly equal to (===) operator.
PHP Operators PHP has a lot of operators, but operators == === strict and arbitrary or perform similar tasks.
- If the two values of different types, and then == === get different results. Computing speed will be different, because == will carry out a type conversion, and compare.
- If the two values are the same type, and then == === get the same result. Almost the same operation speed, two operators are not the type conversion.
Temporarily converted data type == operator compares two values are equal, and === (strict equality operator) does not need to perform any type of conversion, to reduce the amount of calculation, and faster.
Case 1:
<? PHP // 0 == 0 -> the same type of return to true // conversion is complete, and then // check whether the same var_dump (0 == "A"); // ==. 1. 1 -> to true var_dump ( ". 1" == "01"); // == 10 10 -> to true var_dump ( "10" == "1E1"); // == 100 100 -> to true var_dump (100 == "1E2"); // 0 === "a" -> this case to false // only complete conversion // check if there are further // is equal var_dump (0 === "A"); // ". 1" === "01" -> to false var_dump ( ". 1" === "01"); // "10" === "1E1" -> to false var_dump ( "10" === "1E1"); // == 100 "1E2 "->false var_dump(100 === "1e2"); switch ("a") { case 0: echo "In first case"; break; // never match "a" option // because the switch using == Case "a": echo "an In sceond Case"; BREAK; } >?
Output:
bool(true)
bool(true)
bool(true)
bool(true)
bool(false)
bool(false)
bool(false)
bool(false)
In first case
Case 2:
? <PHP // TRUE - The following expression is equivalent to (BOOL) 1 == TRUE var_dump (1 == TRUE); // TRUE - The following expression is equivalent to (BOOL) 0 == FALSE var_dump (0 == FALSE) ; // FALSE - insufficiency. 1 is equal to TRUE //. 1 is a plastic, TRUE is a Boolean var_dump (=== TRUE. 1); // FALSE - 0 insufficiency equal to FALSE // 0 is plastic, FALSE is a Boolean var_dump (0 = FALSE ==); ?>
Output:
bool(true)
bool(true)
bool(false)
bool(false)
Note: === operator 'type comparison relatively safe ", when only two values of the same type and values will returns TRUE, using == equal in value will return TRUE.
Learn more information, please visit:
Above hope to help everyone, many PHPer always encounter some problems and bottlenecks in the advanced time, write more business code no sense of direction, I do not know from where to start to ascend, which I compiled some information, including but not limited to: a distributed architecture, highly scalable, high-performance, high-concurrency, server performance tuning, TP6, laravel, YII2, Redis , Swoole, Swoft, Kafka, Mysql optimization, shell scripts, Docker, micro-services, Nginx, etc. more advanced knowledge required for advanced dry goods can be free for everyone to share, I need to join the official group , click here .