我是 if 简短 if 版本的粉丝,例如:
($thisVar == $thatVar ? doThis() : doThat());
不过我想删除 else 语句,例如:
($thisVar == $thatVar ? doThis());
但是,它不会起作用。有没有我错过的方法?
最佳答案
没有 else
就不能使用它。但你可以试试这个:
($thisVar != $thatVar ?: doThis());
或
if ($thisVar == $thatVar) doThis();
关于PHP:不使用 else 使用简短的 if 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48777723/