title: Php add a key value to associative array in foreach loop
body: <p>I am getting json data from an api endpoint, I would like to add a key value to an array that I get. This is my function:</p>
  
  <pre><code>        $magazines = Magazine::all();
  
          foreach ($magazines as $magazine) {
            $result = file_get_contents('http://customer.pages.com/?customer=' . $magazine-&gt;visio_link_prefix . '&amp;action=latest');
            $issues[] = json_decode($result, true);
          }
  
          foreach ($issues as $issue) {
              Issue::create([
                ''
                'title' =&gt; $issue['papers'][0]['title'],
                'date' =&gt; $issue['papers'][0]['date'],
                'foldername' =&gt; $issue['papers'][0]['foldername'],
                'thumb' =&gt; $issue['papers'][0]['thumb'],
                'thumbmedium' =&gt; $issue['papers'][0]['thumbmedium'],
              ]);
          }
  </code></pre>
  
  <p>The array that I get from the endpoint looks like this:</p>
  
  <pre><code>array:24 [▼
    0 =&gt; array:1 [▼
      "papers" =&gt; array:1 [▼
        0 =&gt; array:11 [▼
          "title" =&gt; "News- 2014-10-22"
          "date" =&gt; "2014-10-22"
          "expires" =&gt; ""
          "catalog" =&gt; 24
          "foldername" =&gt; "News"
          "folder" =&gt; 4965
          "pages" =&gt; 132
          "sectionstarts" =&gt; "1"
          "sectioncount" =&gt; 1
          "thumb" =&gt; "www.customer.pages.com/news/24/teasers/small.jpg"
          "thumb_medium" =&gt; "www.customer.pages.com/news/24/teasers/medium.jpg"
        ]
      ]
    ]
    1 =&gt; array:1 [▶]
    2 =&gt; array:1 [▶]
    3 =&gt; array:1 [▶]
    4 =&gt; array:1 [▶]
    5 =&gt; array:1 [▶]
    6 =&gt; array:1 [▶]
    7 =&gt; array:1 [▶]
    8 =&gt; array:1 [▶]
    9 =&gt; array:1 [▶]
    10 =&gt; array:1 [▶]
    11 =&gt; array:1 [▶]
    12 =&gt; array:1 [▶]
    13 =&gt; array:1 [▶]
    14 =&gt; array:1 [▶]
    15 =&gt; array:1 [▶]
    16 =&gt; array:1 [▶]
    17 =&gt; array:1 [▶]
    18 =&gt; array:1 [▶]
    19 =&gt; array:1 [▶]
    20 =&gt; array:1 [▶]
    21 =&gt; array:1 [▶]
    22 =&gt; array:1 [▶]
    23 =&gt; array:1 [▶]
  ]
  </code></pre>
  
  <p>So, in my foreach loop I would like to add a key value pair <code>'magazineId' =&gt; $magazine-&gt;id</code> to each of the above <code>'papers'</code> arrays. So that later I can use <code>$issue['papers'][0]['magazineId']</code> to get the value of the <code>$magazine-&gt;id</code>. Not sure how to do that?</p>