猿问

3个不同的=

3个不同的=

是什么区别======

我认为使用一个等号是声明一个变量,而两个等号用于比较条件,最后三个等号用于比较声明变量的值。


慕运维8079593
浏览 441回答 4
4回答

FFIVE

你=的赋值操作符,==在“平等”比较操作和===对“相同”的比较操作。$a = $b     Assign      Sets $a to be equal to $b.$a == $b    Equal       TRUE if $a is equal to $b.$a === $b   Identical   TRUE if $a is equal to $b, and they are of the same type. (introduced in PHP 4)有关需要更多信息==和===和的情况下使用每个,看的文档。

慕丝7291255

= 是赋值运算符== 是比较运算符(检查两个变量是否具有相等的值)=== 是相同的比较运算符(检查两个变量是否具有相同的值并且属于同一类型)。

慕容3067478

=赋值运算符==检查两个变量是否具有相同的值===检查两个变量是否具有相同的值以及它们的类型是否相同

一只萌萌小番薯

对于高级PHP用户,知道之间的差别==和===与问自己“是它更快地进行比较==或与===我敢肯定,这两个操作数是相同的类型?”简短而一般的答案是:在这种情况下使用没有性能提升===,所以你应该使用==。感兴趣的标杆它自己的那些,你可以使用下面的代码我写的ad-hoc和尝试不同的价值观$a和$b:<?php&nbsp; &nbsp; // CONFIGURATION&nbsp; &nbsp; $cycles = 1000000;&nbsp; &nbsp; $a = 'random string 1';&nbsp; &nbsp; $b = 'random string 2';&nbsp; &nbsp; // FUNCTIONS&nbsp; &nbsp; function compare_two_equals($a, $b) {&nbsp; &nbsp; &nbsp; &nbsp; if ($a == $b) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return TRUE;&nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return FALSE;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; function compare_three_equals($a, $b) {&nbsp; &nbsp; &nbsp; &nbsp; if ($a === $b) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return TRUE;&nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return FALSE;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; // EXECUTION&nbsp; &nbsp; $time = microtime(TRUE);&nbsp; &nbsp; for ($count_a = 0; $count_a < $cycles; $count_a++) {&nbsp; &nbsp; &nbsp; &nbsp; compare_two_equals($a, $b);&nbsp; &nbsp; }&nbsp; &nbsp; $time_two_a = microtime(TRUE) - $time;&nbsp; &nbsp; $time = microtime(TRUE);&nbsp; &nbsp; for ($count_a = 0; $count_a < $cycles; $count_a++) {&nbsp; &nbsp; &nbsp; &nbsp; compare_three_equals($a, $b);&nbsp; &nbsp; }&nbsp; &nbsp; $time_three_a = microtime(TRUE) - $time;&nbsp; &nbsp; $time = microtime(TRUE);&nbsp; &nbsp; for ($count_a = 0; $count_a < $cycles; $count_a++) {&nbsp; &nbsp; &nbsp; &nbsp; compare_two_equals($a, $b);&nbsp; &nbsp; }&nbsp; &nbsp; $time_two_b = microtime(TRUE) - $time;&nbsp; &nbsp; $time = microtime(TRUE);&nbsp; &nbsp; for ($count_a = 0; $count_a < $cycles; $count_a++) {&nbsp; &nbsp; &nbsp; &nbsp; compare_three_equals($a, $b);&nbsp; &nbsp; }&nbsp; &nbsp; $time_three_b = microtime(TRUE) - $time;&nbsp; &nbsp; $time = microtime(TRUE);&nbsp; &nbsp; // RESULTS PRINTING&nbsp; &nbsp; print "<br />\nCOMPARE == (FIRST TRY): " . number_format($time_two_a, 3) . " seconds";&nbsp; &nbsp; print "<br />\nCOMPARE == (SECOND TRY): " . number_format($time_two_b, 3) . " seconds";&nbsp; &nbsp; print "<br />\nCOMPARE === (FIRST TRY): " . number_format($time_three_a, 3) . " seconds";&nbsp; &nbsp; print "<br />\nCOMPARE === (SECOND TRY): " . number_format($time_three_b, 3) . " seconds";?>注意:只有当每个“FIRST TRY”非常接近“SECOND TRY”时,比较才有效。如果它们明显不同,则意味着处理器在执行比较时忙于执行其他操作,因此结果不可靠并且应该再次运行基准测试。
随时随地看视频慕课网APP
我要回答