Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何改进if算法_Php_Algorithm - Fatal编程技术网

Php 如何改进if算法

Php 如何改进if算法,php,algorithm,Php,Algorithm,如何做得更好?无需重复代码函数(1) 让A=someTrueOrFalse和B=OthersomeTrueOrFalse A | B | outcome ----------------- 0 | 0 | 1 0 | 1 | 1 1 | 0 | 0 1 | 1 | 1 因此: if (!(someTrueOrFalse && !OthersomeTrueOrFalse)) { someFunction(1); } 或者,相当于@axi

如何做得更好?无需重复代码函数(1)


A
=someTrueOrFalse和
B
=OthersomeTrueOrFalse

 A | B | outcome
-----------------
 0 | 0 |    1
 0 | 1 |    1
 1 | 0 |    0
 1 | 1 |    1
因此:

if (!(someTrueOrFalse && !OthersomeTrueOrFalse)) {
    someFunction(1);
}
或者,相当于@axiac的评论

if (!someTrueOrFalse || OthersomeTrueOrFalse) {
    someFunction(1);
}

这取决于两种情况中哪一种看起来更好,我猜(或者有时只是口味的问题)。

这与
如果(!someTrueOrFalse | OthersomeTrueOrFalse)
这更容易理解。@axiac answer的方法看起来更容易理解:只有一个情境函数不能运行:第三个。所以,除了第三个以外的每个案例,都要运行它。您认为这3个案例是真实的,(1、2和4),然后您描述它们。@axiac谢谢,在回答中补充了这一点,尽管我的回答只是想说明如何使用真值表实现这一点。
if (!someTrueOrFalse || OthersomeTrueOrFalse) {
    someFunction(1);
}