### php

#### Effeciently test ifany three of four numbers are equal?

```I am trying to determine a quick way to select sets of numbers (they'll be in arrays). I only need to keep sets where two or more of the numbers are greater than zero; therefore, sets that include zero three times can be discarded. I have come up with the following code but it doesn't have the expected outcomes, any advice would be greatly appreciated.
<?php
function testFour(\$a, \$b, \$c, \$d)
{
if((\$a + \$b + \$c + \$d) == (\$a || \$b || \$c || \$d)) {
echo \$a.", ".\$b.", ".\$c.", ".\$d." => exclude<br>";
} else {
echo \$a.", ".\$b.", ".\$c.", ".\$d." => keep<br>";
}
}
echo "<pre>";
testFour(0,0,0,5); // true
testFour(1,0,0,5); // false
testFour(0,4,2,0); // false
testFour(1,1,0,5); // false
testFour(0,2,0,0); // true
testFour(2,3,0,0); // false
echo "</pre>";
```
```Give this a try:
<?php
function testFour(\$a, \$b, \$c, \$d)
{
\$t = (\$a == 0 ? 1 : 0) + (\$b == 0 ? 1 : 0) + (\$c == 0 ? 1 : 0) + (\$d == 0 ? 1 : 0);
return t < 3;
}
echo "<pre>";
echo "Test1: ".testFour(0,0,0,5)."\n"; // true
echo "Test2: ".testFour(1,0,0,5)."\n"; // false
echo "Test3: ".testFour(0,4,2,0)."\n"; // false
echo "Test4: ".testFour(1,1,0,5)."\n"; // false
echo "Test5: ".testFour(0,2,0,0)."\n"; // true
echo "Test6: ".testFour(2,3,0,0)."\n"; // false
echo "</pre>";```

### Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization