title: PHP foreach loop =>
body: <p>So I've been researching into PHP to create a basic email form and I came across some code which I decided I would take a look at and experiment with. </p>
  
  <p>The HTML form I am working with is: </p>
  
  <pre><code>&lt;form method="post" action="newsjoin.php"&gt; 
  
  &lt;table align=center&gt; 
  &lt;tr&gt;
    &lt;td&gt;&lt;select name="sendto" hidden="hidden"&gt; &lt;option value="newsletter@myDomain.com" selected="selected"&gt;Newsletter&lt;/option&gt; &lt;/select&gt;&lt;/td&gt;
  &lt;/tr&gt; 
  &lt;tr&gt;
    &lt;td&gt;&lt;font color=red&gt;*&lt;/font&gt; Name:&lt;/td&gt;
    &lt;td&gt;&lt;input size=25 name="Name"&gt;&lt;/td&gt;
  &lt;/tr&gt; 
  &lt;tr&gt;
    &lt;td&gt;&lt;font color=red&gt;*&lt;/font&gt; Email:&lt;/td&gt;
    &lt;td&gt;&lt;input size=25 name="Email"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;input type="radio" name="list" value="No" hidden="hidden" /&gt; &lt;input type="radio" name="list" value="Yes" hidden="hidden" checked="checked" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td colspan=2 align=left&gt;&lt;input type=submit name="send" value="Submit"&gt;&lt;/td&gt;
  &lt;/tr&gt; 
  &lt;tr&gt;
    &lt;td&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td colspan=2 align=left&gt;&lt;small&gt;A &lt;font color=red&gt;*&lt;/font&gt; indicates a field is required&lt;/small&gt;&lt;/td&gt;
  &lt;/tr&gt; 
  &lt;/table&gt; 
  
  &lt;/form&gt; 
  </code></pre>
  
  <p>And my newsjoin.php file contains: </p>
  
  <pre><code>&lt;?php 
  $to = $_REQUEST['sendto'] ; 
  $from = $_REQUEST['Email'] ; 
  $name = $_REQUEST['Name'] ; 
  $headers = "From: $from"; 
  $subject = "Web Contact Data"; 
  
  $fields = array(); 
  $fields{"Name"} = "Name";
  $fields{"Email"} = "Email";
  $fields{"list"} = "Mailing List";
  
  $body = "We have received the following information:\n\n"; foreach($fields as $a =&gt; $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 
  
  $headers2 = "From: newsletter@myDomain.com"; 
  $subject2 = "Thank you for contacting us"; 
  $autoreply = "Thank you for subscribing to our mailing list. You should recieve another email shortly confirming our reciept of this information.";
  
  if($from == '') {
      print "You have not entered an email, please go back and try again.";
  } 
  else { 
      if($name == '') {
          print "You have not entered a name, please go back and try again.";
      } 
      else { 
          $send = mail($to, $subject, $body, $headers);       // this is the mail to site staff
          $send2 = mail($from, $subject2, $autoreply, $headers2);     // this is the mail to the user
          if($send) {
              header( "Location: http://www.myDomain.com/newsletter_joined.html" );
          } 
          else {
              print "We encountered an error sending your mail, please notify admin@myDomain.com"; 
          } 
      }
  }
  ?&gt; 
  </code></pre>
  
  <p>Now, this all looks ok to me except for I don't understand this line:</p>
  
  <pre><code>$body = "We have received the following information:\n\n"; foreach($fields as $a =&gt; $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 
  </code></pre>
  
  <p>Namely, I do not understand the <code>$a =&gt; $b</code> section, nor do I understand the use of these variables(if they are variables) in the <code>sprint()</code> function. </p>
  
  <p>I have spent the past 4 hours on Google trying to learn what I can about php being used this way and had no luck. </p>
  
  <p>Thanks!</p>