title: PHP foreach change original array values
body: <p>I am very new in multi dimensional arrays, and this is bugging me big time.</p>
  
  <p>My array is as following:</p>
  
  <pre><code>$fields = array(
      "names" =&gt; array(
           "type"         =&gt; "text",
           "class"        =&gt; "name",
           "name"         =&gt; "name",
           "text_before"  =&gt; "name",
           "value"        =&gt; "",
           "required"     =&gt; true,
      )
  )
  </code></pre>
  
  <p>Then i got a function checking if these inputs are filled in, if they are required.</p>
  
  <pre><code>function checkForm($fields){
      foreach($fields as $field){
          if($field['required'] &amp;&amp; strlen($_POST[$field['name']]) &lt;= 0){
              $fields[$field]['value'] = "Some error";
          }
      }
      return $fields;
  }
  </code></pre>
  
  <p>Now my problem is this line</p>
  
  <pre><code>$fields[$field]['value'] = "Some error";
  </code></pre>
  
  <p>I want to change the content of the original array, since i am returning this, but how do I get the name of the current array (names in this example) in my foreach loop?</p>