Page 1 of 1

array interval

Posted: Tue Jun 17, 2008 7:01 am
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

Re: array interval

Posted: Tue Jun 17, 2008 7:08 am
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