title: adding an element to multidimensional array when within foreach loop (PHP)
body: <p>I'm trying to check if a certain category is allready selected by looping through an array of categories also I want to add another element to the array whci is just a bit to indicate is the category selcated</p>
  
  <p>my categories array looks like this</p>
  
  <pre><code>0=&gt;array(category_id=&gt;12,category_name=&gt;"blogger")  
  1=&gt;array(category_id=&gt;13,category_name=&gt;"dancer")
  </code></pre>
  
  <p>etc...<br>
  now the code i'm trying goes like that:</p>
  
  <pre><code>foreach ($userCategories as $key=&gt;$category) {
      if($category['category_id'] == $mediaDetails['currentCategory']) {
          $category['current'] = 1;
      } else {
          $category['current'] = 0;
      }
  }
  </code></pre>
  
  <p>when executing</p>
  
  <pre><code>die(var_dump($userCategories));
  </code></pre>
  
  <p>I expect to get an array similar to  </p>
  
  <pre><code>0=&gt;array(category_id=&gt;12,category_name=&gt;"blogger",current=&gt;0)  
  1=&gt;array(category_id=&gt;13,category_name=&gt;"dancer",current=&gt;1)
  </code></pre>
  
  <p>but instead I get the same array I had before the foreach loop</p>
  
  <p>any ideas?</p>
  
  <p>Thanks</p>