title: Add values to $_SESSION['name'] then Loop thru values
body: <p>I'm using a $_SESSION variable to store error codes in an app I'm creating.
  On my form processing page, i'm using the following code (as an example):</p>
  
  <pre><code>session_start();
  $_SESSION['site_msg']   = array();
  if(1 == 1) {
      $_SESSION['site_msg'] = 18;
  }
  if(2 == 2) {
      $_SESSION['site_msg'] = 21;
  }
  if(3 == 3) {
      $_SESSION['site_msg'] = 20;
  }
  </code></pre>
  
  <p>I'm hoping to use a function to get the values from the array to use elsewhere in my code.</p>
  
  <pre><code>function error_code() {
      foreach($_SESSION['site_msg'] as $value) {
          echo "Value: $value &lt;br /&gt;";
      }
  }
  </code></pre>
  
  <p>The above gives an error; Warning: Invalid argument supplied for foreach() ...</p>
  
  <p>If I write the function like this:</p>
  
  <pre><code>$array[] = $_SESSION['site_msg'];
  foreach($array  as $value) {
  echo  "VAL: " . $value;
  }
  </code></pre>
  
  <p>It only gives me the last value, 20.</p>
  
  <p>Anyone have an idea where I went wrong?
  Thanks!</p>