How to insert nested array of data into mysql using php
<p>Currently I have an nested Array having three arrays (items,customer,address) that looks like the following when it output through  </p>

<pre><code>print_r($_POST);

Array
(
    [items] =&gt; Array
        (
            [0] =&gt; Array
                (
                    [item_id] =&gt; 1
                    [item_price] =&gt; 2
                    [quantity] =&gt; 11
                )

            [1] =&gt; Array
                (
                    [item_id] =&gt; 12
                    [item_price] =&gt; 13
                    [quantity] =&gt; 14
                )

            [2] =&gt; Array
                (
                    [item_id] =&gt; 13
                    [item_price] =&gt; 14
                    [quantity] =&gt; 15
                )

            [3] =&gt;; Array
                (
                    [item_id] =&gt; 16
                    [item_price] =&gt; 17
                    [quantity] =&gt; 18
                )

            [4] =&gt; Array
                (
                    [item_id] =&gt; 18 
                    [item_price] =&gt; 38
                    [quantity] =&gt; 38
                )

        )

    [customer] =&gt; 111
    [address] =&gt; 171
)
</code></pre>

<p>I would like to insert this data into one table with each element value belonging to its respective field.</p>

<p>Currently <strong>my php code</strong> looks like the following</p>

<pre><code>if(is_array($_POST)){
    foreach($_POST as $key =&gt; $value){

    $item_id = (int) $value['item_id'];
    $item_price = (int) $value['item_price'] ;
    $quantity = (int) $value['quantity'] ;

    $sql = "INSERT INTO orderItems(item_id, item_price, quantity) values ('$item_id', '$item_price', '$quantity')";
    mysql_query($sql) or exit(mysql_error()); 
    }
}
</code></pre>

<p>it's not working properly. I am new to this. Can anybody help?</p>