我有一个像这样的条件
if ( ( $red == '50' && $city == 'Bali' ) || ( $red == '50' && $city == 'BALI' ) ) {
//My code here
}
Run Code Online (Sandbox Code Playgroud)
我如何结合条件并写一行.php中有任何功能吗?
有一个函数用于完全不区分大小写的比较函数调用strcasecmp,它匹配Bali和BaLi和BALI以及任何其他情况组合,假设asfii/ascii-utf8的子集
if ($red == '50' && 0 === strcasecmp($city,'Bali') )
Run Code Online (Sandbox Code Playgroud)
if ($red == '50' && mb_strtolower($city,'UTF-8') ==='åsgårdstrand')- 如果你特别使用UTF-8,你也可以使用preg_match与/ui修饰符,如if ($red == '50' && preg_match('/^'.preg_quote('Bøli').'$/ui',$city) )
只需将字符串转换为大写或小写,然后进行比较:
if ( $red == '50' && strtolower($city) === 'bali' ) {
//My code here
}
Run Code Online (Sandbox Code Playgroud)
要么
if ( $red == '50' && strtoupper($city) === 'BALI' ) {
//My code here
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
275 次 |
| 最近记录: |