Jump to content

[SOLVED] if two or more are greater than zero


Crusader

Recommended Posts

I have eight variables stored, for example:
$first, $second, $third, $fourth, $fifth, $sixth, $seventh, $eigth

Is there an easier way to determine if two or more of them are greater than zero other than looping through it to make all the possible combinations?

Thanks.
I dont think there's another way. I may be wrong, but that's what I would do:

[code]<?php

$positives = 0;
$numbers = array($first, $second, $third, $fourth, $fifth, $sixth, $seventh, $eigth);
foreach ($numbers as $num)
{
if($num > 0)
$positives ++;
}
echo "There are ".$positives." positive numbers.";

?>[/code]

Orio.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.