Blogger Information
Blog 11
fans 0
comment 0
visits 9151
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
太空船比较运算符小知识
PHP新手学习记录
Original
1505 people have browsed it

今天的学习中初识 php7 新增的结合比较运算符,它的作用按照符号顺序是:

$a 小于、等于、大于 $b 时,分别返回一个小于、等于、大于 0 的整型值。经测试:

  1. $x = 1;
  2. $y = 2;
  3. echo $x <=> $y; // 输出 -1
  4. $x = 2;
  5. $y = 2;
  6. echo $x <=> $y; // 输出 0
  7. $x = 2;
  8. $y = '2';
  9. echo $x <=> $y; // 输出 0
  10. $x = 2;
  11. $y = 1;
  12. echo $x <=> $y; // 输出 1

说明 结合比较运算符 <=> 比较的是类型转换后的值,也就是 php 中的 ==(等于),而不是 === (全等)。

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post