title: Handling associative array and foreach in PHP
body: <p>I'm trying to write a generic function for my mailing system.</p>
  
  <p>What I'm planning to do is.</p>
  
  <ol>
  <li>Get all the to-address values in an array and the required information</li>
  <li>Store all the values in the database.</li>
  </ol>
  
  <p>I started with two dimensional associate array, but I'm not able to retrieve the values in the foreach.</p>
  
  <p>Finally the foreach echo statement should be like</p>
  
  <pre><code>insert into my_table('name','to_address','subject','message','add_cc') values ('Author1','author1@gmail.com','Subject','Message','test@gmail.com');
  insert into my_table('name','to_address','subject','message','add_cc') values ('Author2','author2@gmail.com','Subject','Message','test@gmail.com');
  insert into my_table('name','to_address','subject','message','add_cc') values ('Author3','author3@gmail.com','Subject','Message','test@gmail.com');
  </code></pre>
  
  <p>Here below is my code, I know the problem is with the foreach loop. I would be happy even if the associate array is minimized without the numeric sequence lik [0],[1],[2].</p>
  
  <pre><code>&lt;?php
  $to_address = array(
      array( 'Name' =&gt; "Author1", 'Email' =&gt; 'author1@gmail.com' ),
      array( 'Name' =&gt; "Author2",  'Email' =&gt; 'author2@gmail.com' ),
      array( 'Name' =&gt; "Author3", 'Email' =&gt; 'author3@gmail.com')
  );
  
  $subject = "Subject";
  $message = "Message";
  $add_cc  = "test@gmail.com";
  sendMail($to_address,$subject,$message,$add_cc);
  
  function sendMail($to_address,$subject,$message,$add_cc) {
      foreach ($to_address as $key =&gt; $val) {
          foreach ($val as $key1 =&gt; $val1) {
              print_r($val1);
          }
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>Thanks,
  Kimz</p>
  
  <p>EDIT:</p>
  
  <p>In other words, I'm not able to loop the $to_address value and I need a help.</p>