Possible Duplicate:
Able to see a variable in print_r()'s output, but not sure how to access it in code
Can I store an array in a variable?
I have this array:
$_POST['product']
and when I print it:
echo "<PRE>";
print_r($_POST['product']);
echo "</PRE>";
the result is:
<PRE>Array
(
[0] => Array
(
[0] => 1
[1] => cola
[2] => wwww
[3] => 1
[4] => 2.00
[5] => 0.00
[6] => 2.00
)
)
</PRE>
How can I store the value of the array in a variable? For example, I need to insert [1] => cola into the table in the database.
You can access the array like
$_POST['product'][0][1]to get the value of cola.For multiple inserting to database you should use foreach loop or for loop.
UPDATED
Alright,
Foreach Loop
I prefered to use for loop .
THere is also an optimize way for inserting in the database by avoiding the insert sql inside the for/foreach loop..
But for now that should work for you.. 🙂