Array Of Numbers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Array Of Numbers

Post by icesolid »

What would be the best way of determining if a number equals 150 or 159 or any number in between 150-159?

Would an array be the best way or would it be easier with an if statement?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you mean the sum of the values? array_sum()
or do you mean the number of values? count()
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

No

Post by icesolid »

No I want to determine a variables value, if its equal to something.

EX:

if($var = anything in between 150 and 159 or equal to 150 or 159) {
do this
} else {
do this
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

if ($var >= 150 and $var <= 159)
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

Code: Select all

foreach ($array_of_numbers as $val)
{
    if ($val > 149 && $val < 160)
    {
        //you have a match! run with it baby, ya!
    }
}
edit: once again, I am beat by feyd
Post Reply