我对xor验证感到麻烦。
我想用给定的两个输入进行验证。
例如,
$input1 = true;
$input2 = true;
$result = validateFunction($input1, $input2);
// $result is false
true仅允许一个输入。 如果两个输入都为真,我想限制。
我认为可以通过function($ context){}实现。
但是,notEmpty和allowEmpty不适合。
因为如果$ result为false,则输入之一应为空。
而且notEmpty和allowEmpty不会强制输入为空。
我认为我应该制定自定义验证规则。
有人知道吗非常感谢。
答案 0 :(得分:0)
如果我对您的理解正确,是否要创建一个简单的xor验证?如果是这样,只需使用&&
运算符:
long lastTime = System.currentTimeMillis();
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
float newZ = sensorEvent.values[2];
long newTime = System.currentTimeMillis();
// Only print the answer when the device is flipped down
// and there wasn't an answer for at least 1 second.
long timeDiff = (newTime - lastTime) / 1000.0; // seconds
if (zvalue > 9 && newZ < 9 && timeDiff > 1)
printAnswer();
zvalue = newZ;
lastTime = newTime;
}
有关更多信息:https://www.php.net/manual/en/language.operators.bitwise.php