title: How to insert array of data into mysql using php
body: <p>Currently I have an Array that looks like the following when output thru print_r();</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [R_ID] =&gt; 32
              [email] =&gt; a@a.com
              [name] =&gt; Bob
          )
  
      [1] =&gt; Array
          (
              [R_ID] =&gt; 32
              [email] =&gt; b@b.com
              [name] =&gt; Dan
          )
  
      [2] =&gt; Array
          (
              [R_ID] =&gt; 32
              [email] =&gt; c@c.com
              [name] =&gt; Paul
          )
  
      [3] =&gt; Array
          (
              [R_ID] =&gt; 35
              [email] =&gt; d@d.com
              [name] =&gt; Mike
          )  
  )
  </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 my php code looks like the following</p>
  
  <pre><code>if(is_array($EMailArr)){
      foreach($EMailArr as $R_ID =&gt; $email =&gt; $name){
  
      $sql = "INSERT INTO email_list (R_ID, EMAIL, NAME) values ('$R_ID', '$email', '$name')";
      mysql_query($sql) or exit(mysql_error()); 
      }
  }
  </code></pre>
  
  <p>*Note : R_ID is NOT the primary key in this table.*</p>
  
  <p>Can someone help me understand how I should approach this situation? Thank you for reading and your help!</p>
  
  <p>Regards.</p>