for loop and if loop is refusing to print a varriable outside the loop?
<p>i am facing a problem that after i created the jQuery post, i was able to receive all the data but as a one peace, so when i began rephrasing them i succeed until the final part which was the inserting into the database, where inside the for loop and if loop i am getting the value but when i wanted to start inserting them into the database i am getting null values, below is the for loop and if loop</p>

<pre><code>if ($action == "insert")
{
    $fields = explode("&amp;",$data);

    foreach($fields as $field)
    {
        $field_key_value = explode("=",$field);
        $key = urldecode($field_key_value[0]);
        $value = urldecode($field_key_value[1]);

        $id = $row['id'];

        $date1 = date("d/n/Y");

        foreach ($cart-&gt;get_contents() as $item)
        {
            $item_id    = $item['id'];
            $item_name  = $item['name'];
            $item_price = $item['price'];
            $item_qty   = $item['qty'];
            $item_ids       = explode("-",$item_id);

            for($i = 0; $i &lt; count($item_ids); $i++)
            {
                $item_idn = join("",$item_ids);
            }

            if($key == $item_id."id")
            {
                $ids = $value;
                echo $ids."\r\n";
            }
            elseif($key == "Small".$item_idn)
            {
                $small= $value;
                echo $small."\r\n";
            }
            elseif($key == "large".$item_idn)
            {
                $large= $value;
                echo $large."\r\n";
            }
            elseif($key == "medium".$item_idn)
            {
                $medium= $value;
                echo $medium."\r\n";
            }
            elseif($key == "xlarge".$item_idn)
            {
                $xlarge= $value;
                echo $xlarge."\r\n";
            }
            elseif($key == "qty".$item_idn)
            {
                $qty = $value;
                echo $qty."\r\n";
            }
            elseif($key == "Total".$item_idn)
            {
                $subtotal = $value;
                echo $subtotal."\r\n";
            }
            elseif($key == "finaltotal")
            {
                $finaltotal = $value.",";
                $final = explode(",",$finaltotal);

                for($i = 0; $i &lt; count($final); $i++)
                {
                    $totalf = $final[$i];
                    break 3;
                }
            }
        }
    }
}
</code></pre>
