# Re: [PHP] Advice needed

```On Sat, Mar 23, 2002 at 05:19:05AM +0000, James Newkid wrote:
> so if \$Quantity1 is 10
> and \$Price1 is \$1.00
> that means each "unit" is .10
>
> so the output would be
> q1 q2 q3 q5 q10 q15 q20 q25 q50 q100 q300 q500 q600 q1000000000
> 0  0  0  0  .10 .10 .10 .10 .10 .10  .10  .10  .10  .10
>
> Now the tricky part is \$Quantity2 can either be blank or have a value
> and if \$Quantity2 has a value then \$Quantity3 can either be blank or have a
> value
>
> SO If \$Quantity2 is 500
> and \$Price2 is \$40.00
> the output would now be
> q1 q2 q3 q5 q10 q15 q20 q25 q50 q100 q300 q500 q600 q1000000000
> 0  0  0  0  .10 .10 .10 .10 .10 .10  .10  .08  .08  .08
> ```
```
This had 7 people stumped? Fire them :)

I think you had something like this in mind:

----8<-----
<?
function CalcPPU(\$quantity, \$price)
{
global \$ppu;
global \$quant;

for(\$i=0;\$i<count(\$quant);\$i++)
{
if(\$quant[\$i]>=\$quantity)
{
\$ppu[\$i]=\$price/\$quantity;
}
}
}

\$quant=array(1,2,3,5,10,15,20,25,50,100,300,500,600,10000);

\$Quantity1=10;
\$Price1=1;
\$Quantity2=500;
\$Price2=40;

\$ppu=array();
for(\$i=0;\$i<count(\$quant);\$i++)
{
\$ppu[\$i]=0;
}

if(\$Quantity1)
{
CalcPPU(\$Quantity1, \$Price1);
if(\$Quantity2)
{
CalcPPU(\$Quantity2, \$Price2);
if(\$Quantity3)
{
CalcPPU(\$Quantity3, \$Price3);
}
}
}

for(\$i=0;\$i<count(\$quant);\$i++)
{
echo "|\$quant[\$i]";
}
echo "\n";
for(\$i=0;\$i<count(\$quant);\$i++)
{
echo "|\$ppu[\$i]";
}
echo "\n";
?>
----8<-----

Output:
|1|2|3|5|10|15|20|25|50|100|300|500|600|10000
|0|0|0|0|0.1|0.1|0.1|0.1|0.1|0.1|0.1|0.08|0.08|0.08

--

Daniel Tryba
PGP public key: http://www.stack.nl/~muaddib/pgp.txt

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

```