布尔值切换/反转
PHP中是否有切换/反转boolean
值的功能?
Is there a function for switching/inverting boolean
value in PHP?
喜欢...的快捷方式:
Like... a shortcut for:
if($boolean === true){
$boolean = false;
}else{
$boolean = true;
}
推荐答案
是的:
$boolean = !$boolean;
如果不是布尔值,可以使用三元构造:
if it's not a boolean value, you can use the ternary construction:
$int = ($some_condition ? 1 : 2); // if $some_condition is true, set 1
// otherwise set 2
相关文章