Save Array Key and Value at the same time in Database with MSSQL and PHP
<p>I want to save key  and value of an array inside a foreach loop in a database with mssql and php.</p>

<p>Here is my array, i encoded it on json ($myArr):</p>

<pre><code>{
  "UPC-A": "55055",
  "EAN-13": "7077707",
  "UPC": "0940",
  "GTIN": "009642",
  "GTIN-14": "566642"
}
</code></pre>

<p>This is my code:</p>

<pre><code>foreach($myArr as $key =&gt; $val){
   $insert = "Insert Into tbl (barcodeType,barcode) Values ($key, $val)"
   $stmtBar = $db-&gt;prepare($insertBarcode);  
   $stmtBar-&gt;execute();
   //what is the best approach for this???    
}
</code></pre>

<p>The output should be like this when encode in json from database:</p>

<pre><code>{
"barcodeType": "UPC-A",
"barcode": "55055"
},
{
"barcodeType": "EAN-13",
"barcode": "7077707"
}
</code></pre>