array interval

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
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

array interval

Post by pedroz »

With the following array

$ar = array (
//color, amount, 1/0
"red,10,0",
"red,20,1",
"red,30,0",
"red,40,1",
//"red,n,0 or 1" n: means infinite
"blue,10,0",
"blue,20,1",
"blue,30,0",
"blue,40,1",
//"blue,n,0 or 1" n: means infinite
);

I would have a function with the following echo
if color=red && amount=10 then 0
if color=red && amount=11 then 1
if color=red && amount=20 then 1
if color=red && amount=21 then 0
...
if color=blue && amount=25 then 0

many thanks
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: array interval

Post by WebbieDave »

iterate through the array, explode each element on the comma, iterate through this new array.

http://us.php.net/manual/en/control-structures.for.php
http://us.php.net/manual/en/function.explode.php
Post Reply