PHP array empty after pushing in foreach
<p>I am pushing values inside an array in foreach loop and the values seem to be added in the array so the problem is not in the pushing condition. However when I go through that array again, it is empty.</p>

<p>Can please anyone explain to me, why this code</p>

<pre><code>foreach ($allItems as $pair) {
    for ($i = 0; $i &lt; count($keywords); $i++) {
        if ($this-&gt;itemInArray($pair["item"], $items2D[$i])) {
            array_push($pair["keywords"], $keywords[$i]-&gt;getWord());
        }
    }
    $this-&gt;log("Keywords count inside loop: ".count($pair["keywords"]));
}

foreach ($allItems as $pair) {
    $this-&gt;log("Keywords count outside loop: ".count($pair["keywords"]));
}
</code></pre>

<p>Outputs this:</p>

<pre><code>Keywords count inside loop: 3
Keywords count inside loop: 1
Keywords count inside loop: 1
Keywords count inside loop: 1
Keywords count outside loop: 0
Keywords count outside loop: 0
Keywords count outside loop: 0
Keywords count outside loop: 0
</code></pre>

<p>what am I doing wrong and how to fix it?</p>