title: Cannot change the value of an array in php
body: <p>I have a global array variable I am using to store some values from a <code>$_POST</code> variable.  Because I am modifying them within an <code>if</code> statement I have used the word <code>global</code>.  I have already populated the array as <code>array(0,1)</code>.  Given that the values are modified within my <code>if</code> statements, I am still getting the initialised values that I started with.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Here is my <code>formHandler.php</code> code:</p>
  
  <pre><code>   // get form ID
  $formID = $_GET['id'];
  
  // create a global array
  $results = array();
  
  // check to see what ID has be retrieved
  if ($formID == 1) {
      $value = $_POST['emotion'];
      $results[0] = $value;
      // 302 redirect
      header("location: page02.php?results1=$results[0]");
  } 
  else if ($formID == 2) {
      $value = $_POST['emotion02'];
      $results[1] = $value;
      // 302 redirect
      header("location: page03.php?&amp;results2=$results[1]");
  }
  </code></pre>
  
  <p>Here is my <code>page01.php</code> code:</p>
  
  <pre><code>  &lt;h1&gt;This is Page 01&lt;/h1&gt;
  
      &lt;form id="form" action="formHandler.php?id=1" method="POST"&gt;
  
              &lt;p&gt;&lt;input type="radio" value="happy" name="emotion"&gt;Happy
              &lt;input type="radio" value="excited" name="emotion"&gt;Excited
              &lt;input type="radio" value="angry" name="emotion"&gt;Angry
              &lt;input type="radio" value="frustrated" name="emotion"&gt;Frustrated
              &lt;input type="radio" value="miserable" name="emotion"&gt;Miserable
              &lt;input type="radio" value="sad" name="emotion"&gt;Sad
              &lt;input type="radio" value="tired" name="emotion"&gt;Tired
              &lt;input type="radio" value="calm" name="emotion"&gt;Angry&lt;/p&gt;
  
              &lt;p&gt;&lt;input type="submit" name="submit" value="Submit"&gt;&lt;/p&gt;
  </code></pre>
  
  <p>Here is my <code>page02.php</code> code:</p>
  
  <pre><code>&lt;h1&gt;This is Page 02&lt;/h1&gt;
  
      &lt;form id="form" action="formHandler.php?id=2" method="POST"&gt;
  
              &lt;p&gt;&lt;input type="radio" value="happy" name="emotion02"&gt;Happy
              &lt;input type="radio" value="excited" name="emotion02"&gt;Excited
              &lt;input type="radio" value="angry" name="emotion02"&gt;Angry
              &lt;input type="radio" value="frustrated" name="emotion02"&gt;Frustrated
              &lt;input type="radio" value="miserable" name="emotion02"&gt;Miserable
              &lt;input type="radio" value="sad" name="emotion02"&gt;Sad
              &lt;input type="radio" value="tired" name="emotion02"&gt;Tired
              &lt;input type="radio" value="calm" name="emotion02"&gt;Angry&lt;/p&gt;
  
              &lt;p&gt;&lt;input type="submit" name="submit" value="Submit"&gt;&lt;/p&gt;
  </code></pre>
  
  <p>Here s my <code>page03.php</code> code:</p>
  
  <pre><code>&lt;?php include("formHandler.php"); ?&gt;
  
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Audio Survey&lt;/title&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;h1&gt;Thanks for your submission&lt;/h1&gt;
  
          &lt;?php
  
          $results = array();
          $results[0] = $_GET['results1'];
          $results[1] = $_GET['results2']; 
  
          echo "&lt;p&gt;" . $results[0] . " " . $results[1] . "&lt;/p&gt;"; 
  
          ?&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>