title: PHP Multidimensional Array or better option?
body: <p>I have a code that takes posted data from form A and then find the prices of goods and display them. Now i need to do more with the following data in the body of the 2nd form:
  Item name
  Item Qty
  Item Price</p>
  
  <p>The code is here:</p>
  
  <pre><code>&lt;?php
  echo "&lt;div style='width:30%; height:auto; border: 2px solid;'&gt;";
      echo "&lt;h1&gt;The Items Are...&lt;/h1&gt;&lt;br&gt;";
      //array that will hold the sum of each item cost
      $totalAmountArray = array();
  
      foreach ($_POST['basket'] as $name =&gt; $value) 
      {
          //indexer for totalAmountArray
          $i=0;
          if($value &gt; 0){
                  //echo $name . ": " . $value . "&lt;br&gt;";
  
              $itemPrice;
              //reassign 
              $itemName = $name;
  
              $itemQty = $value;
              //sql connection..
              mysql_connect();
              mysql_select_db("xxxxxx");
              $result = mysql_query("SELECT * FROM pricing WHERE item = '".$name."'");
              while($row = mysql_fetch_array($result)){
                  $itemPrice = $row['price'];
                  /*DEBUGGING*/
                  echo "Item Name: &lt;b&gt;".$itemName . " &lt;/b&gt;@ ";
                  echo "&lt;b&gt;".$itemPrice ." &lt;/b&gt;X ".$itemQty."&lt;br&gt;";
              }//end of while loop
  
              //multiply to get total for this item - store in temp
              $temp = $itemQty * $itemPrice;
              //store temp at index i in totalAmountArray
              array_push($totalAmountArray, $temp);
              unset($result);
              unset($itemPrice);
              unset($itemQty);
              unset($temp);
          }//end of if-statement
      }//end of foreach
      echo "&lt;h1&gt;Total Amount:&lt;br&gt;&lt;/h1&gt; ";
      //print_r($totalAmountArray);
      $sum;
      foreach($totalAmountArray as $perItemPrice){
          $sum += $perItemPrice;
      }
      echo "&lt;b&gt;SR. ".$sum."&lt;/b&gt;";
  echo "&lt;/div&gt;";
  ?&gt;
  </code></pre>
  
  <p>I am thinking of storing all the details returned from above foreach's into multidimensional array to have something like this:</p>
  
  <pre><code>[0] =&gt; itemName =&gt; itemQty =&gt; itemPrice &lt;br&gt;
  [1] =&gt; itemName =&gt; itemQty =&gt; itemPrice &lt;br&gt;
  [2] =&gt; itemName =&gt; itemQty =&gt; itemPrice &lt;br&gt;
  [3] =&gt; itemName =&gt; itemQty =&gt; itemPrice &lt;br&gt;
  .....
  </code></pre>
  
  <p>would this be the best way? and how can it be done? I am really unfamiliar with multidimensional arrays in practice (only in theory). </p>
  
  <p>Thanks a lot for the help and advice, </p>