Page 1 of 1

Foreach and adding

Posted: Thu Sep 23, 2004 9:57 pm
by AlbinoJellyfish
I have a script that adds checkboxes values to an array, and I can print them out using

Code: Select all

<?php
foreach($_POST['array'] as $key => $value) {
echo $value."<br />";
 }
?>
Each checkbox corresponds to a product, and then adds it to the array, and when i print the array on the second page, how do I get the values separated so I can put the prices on?

Suppose I check Calea. On the post page, i include a file with a bunch of variables, and Calea is assigned the price of 5. How do I see if calea is in the array, and then add 5 dollars to a sum if it is?

Posted: Thu Sep 23, 2004 9:58 pm
by AlbinoJellyfish
my check boxes look like this:

Code: Select all

&lt;input name="array&#1111;]" type="checkbox" id="CALEA" value="CALEA"&gt;
prices:

Code: Select all

<?php
$R2 = "5";
$GR303 = "10";
$IDSN-PRI = "40";
$V5 = "60";
$TR08 = "100";
$CALEA = "27";
$SS7 = "92";

?>

Posted: Thu Sep 23, 2004 9:59 pm
by feyd
there's a wonder function called [php_man]in_array[/php_man] :roll:

I'd strongly suggest storing those prices in an array, it's easier to access.

Posted: Thu Sep 23, 2004 10:08 pm
by AlbinoJellyfish
Thanks, this is my first time using arrays and couldnt find that. Those prices will soon be stored in a mysql database, im just getting the code for the order form down.