 <p>Your problem is a misunderstanding of how PHP provides your "value" in the foreach construct.</p> <pre><code>foreach($top_level_array as $current_top_level_member) </code></pre> <p>The variable $current_top_level_member is a copy of the value in the array, not a reference to inside the $top_level_array. Therefore all your work happens on the copy and is discarded after the loop completes. (Actually it is in the $current_top_level_member variable, but $top_level_array never sees the changes.)</p> <p>You want a reference instead:</p> <pre><code>foreach($top_level_array as $key =&gt; $value) { $current_top_level_member =&amp; $top_level_array[$key]; </code></pre> <p><strong>EDIT:</strong></p> <p>You can also use the <code>foreach</code> by reference notation (hat tip to air4x) to avoid the extra assignment. Note that if you are working with an array of Objects, they are already passed by reference.</p> <pre><code>foreach($top_level_array as &amp;$current_top_level_member) </code></pre> <p>To answer you question as to why PHP defaults to a copy instead of a reference, it's simply because of the rules of the language. Scalar values and arrays are assigned by value, unless the <code>&amp;</code> prefix is used, and objects are always assigned by reference (<a href="http://www.php.net/manual/en/language.references.whatdo.php" rel="nofollow">as of PHP 5</a>). And that is likely due to a general consensus that it's generally better to work with copies of everything expect objects. BUT--it is not slow like you might expect. PHP uses a lazy copy called copy on write, where it is really a read-only reference. On the first write, the copy is made.</p> <blockquote> <p>PHP uses a lazy-copy mechanism (also called copy-on-write) that does not actually create a copy of a variable until it is modified.</p> <p>Source: <a href="http://www.thedeveloperday.com/php-lazy-copy/" rel="nofollow">http://www.thedeveloperday.com/php-lazy-copy/</a></p> </blockquote>