Home > Backend Development > PHP Tutorial > php comparison operators

php comparison operators

不言
Release: 2023-03-24 15:30:01
Original
1685 people have browsed it

This article introduces the comparison operators in PHP, which has certain reference value. Now I share it with you. Friends in need can refer to it

1. If you compare a number and a string Or comparing strings involving numeric content, the strings will be converted into numerical values ​​and the comparison will be performed according to the numerical values ​​

2,

$a < ;=> $b Combined comparison operators When less than, equal to, or greater than than, return a value less than (-1), equal to (0), or greater than 0 (1) respectivelyinteger value. PHP7 starts to provide.
$a ?? $b ?? $c NULL merge operator The first one from left to right exists and An operand that is not NULL. If neither is defined and is not NULL, NULL is returned. Available starting with PHP7.
switch ("a") {
case 0:
    echo "0";//会运行到这里了因为"a"和数字0比较,字符串被转换成0。如果case “a”放在第一个,那么会运行到case "a"的程序
    break;
case "a": // never reached because "a" is already matched with 0
    echo "a";
    break;
}
Copy after login

Related recommendations:

PHP uses qqwry.bat to obtain the actual address

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template