title: Add a new field to array elements in a foreach PHP - Laravel
body: <p>I have this variable:</p>
  
  <pre><code>$families = array(
      array(
          'expand'      =&gt; '',
          'family_id'   =&gt; 'AAER',
          'active'      =&gt; true,
          'description' =&gt; 'Wall Art',
          'group_id'    =&gt; 5
      ),
      array(
          'expand'      =&gt; '',
          'family_id'   =&gt; 'EERR',
          'active'      =&gt; true,
          'description' =&gt; 'Personalised Mugs',
          'group_id'    =&gt; 4
      ),
  );
  </code></pre>
  
  <p>And I want add to my $families items a field called 'href', like this:</p>
  
  <pre><code>$families = array(
      array(
          'href'        =&gt; 'http://mipage/wall-art/AAER',
          'expand'      =&gt; '',
          'family_id'   =&gt; 'AAER',
          'active'      =&gt; true,
          'description' =&gt; 'Wall Art',
          'group_id'    =&gt; 5
      ),
      array(
          'href'        =&gt; 'http://mipage/personalised-mug/EEER',
          'expand'      =&gt; '',
          'family_id'   =&gt; 'EERR',
          'active'      =&gt; true,
          'description' =&gt; 'Personalised Mugs',
          'group_id'    =&gt; 4
      ),
  );
  </code></pre>
  
  <p>To do this I iterate $families in a foreach loop:</p>
  
  <pre><code>foreach($cat['families'] as $cat_fam) {
      $cat['families'][]['href']  = 'http//mysite/'.str_slug($cat_fam).'/'.$cat_fam['family_id'];
  }
  </code></pre>
  
  <p>But this not works for me.</p>
  
  <p>How can I make this?</p>