title: Form submission: PHP S_SESSION statements within a foreach loop
body: <p>Let's suppose I have the following PHP code which attempts to read from an array called <code>$arr</code> which takes on the values <i>{fullname, studentnumber, email}</i>. Upon submission of my HTML form, this PHP code will execute the foreach loop, and store the values posted to the page in the <code>$_SESSION</code> array.</p>
  
  <pre><code>foreach($arr as $field):
      $_SESSION[$field] = $_POST[$field];
  endforeach;
  </code></pre>
  
  <p>The above code doesn't work as intended. If I were to replace the above code block with the code below, the values in the fields on my page get stored correctly in the <code>$_SESSION</code> array.</p>
  
  <pre><code>$_SESSION[fullname] = $_POST[fullname];
  $_SESSION[studentnumber] = $_POST[studentnumber];
  $_SESSION[email] = $_POST[email];
  </code></pre>
  
  <p>How do I accomplish this, in an efficient and expandable way? I don't want to have to write new $_SESSION statements every time I add a new field to my form.</p>
  
  <p>EDIT: // The first block of code actually works as intended. There was a typo originally!</p>