php variable copy in loop strange behaivor
<p>Good day. Faced a problem that looks somehow like this:
I have a variable, that in loop is reset and refilled. I assign that variable to other variable as it's property(Like $item->subitems). 
Ater that I collect $item to an array of $items for example.
Each loop this variable is re-set and re-filled, and contains different data.
Approximate sample code goes below:</p>

<pre><code>&lt;?php
$seasons = array(1,2);
$ltabs= array(1);
$all = array(1,2,3,4,5,6,7,8,9,0);
        foreach ($ltabs as $tab)
        {
            //Resetting an object instance
            $itm=false;
            //Re-Initing object
            if (1==1)
            {
                $itm-&gt;height = 1;
                $itm-&gt;width  = 2;
            }
            else
            {
                $itm-&gt;height = 3;
                $itm-&gt;width  = 4;
            }
            //And thats where crap happens
            //foreach($seasons as $season) //Dont work that way too
            for ($y=0;$y&lt;count($seasons);$y++)
            {
                //Re-initing local array for needed values
                $itemz=array();
                //$itm-&gt;items = array();
                for($a=0;$a &lt; count($all);$a++) {
                    if ($all[$a] % $seasons)//Not tested, supposed to gove ANY dofference in arrays. 
                    {
                        $itemz[]=$all[$a];
                    }
                 }
                $itm-&gt;items = $itemz;
                $rtabs[$season] = $itm;
                unset($itemz);
                //unset($itemz);
            }
        }
        //Returns crap.
        var_dump($rtabs);
?&gt;
</code></pre>

<p>But when I try to</p>

<pre><code>&lt;?php
foreach($rtabs as $itm)
{
    var_dump($itm-&gt;items);
}
?&gt;  
</code></pre>

<p>I see that all these subitems contain same set of data.
I have sucseeded to defeat it only by re-assigning whole $itm variable in this sub-loop. But I'd like to undeerstand - why does it acts that way?..
According to <a href="http://docstore.mik.ua/orelly/webprog/php/ch02_03.htm" rel="nofollow">this</a> article - garbage collector and php's  copy-on-write thing should be initialised when I've resetted this $itemz array, so to me all this looks quite unlogickal.
Any help would be appreciated.</p>
