Reply to Re: safe to delete elements of array in foreach

Your name:

Reply:


Posted by Jerry Stuckle on 05/21/07 17:41

Rami Elomaa wrote:
> gosha bine kirjoitti:
>> On 20.05.2007 05:09 Jon Slaughter wrote:
>>
>>>
>>> Well, your right. I assume that when it says copy it means a deep
>>> copy. If so then essentially its working on a different variable...
>>
>> From my understanding, foreach doesn't make a copy of *entire array*,
>> it just copies *current value* into the loop variable (unless you
>> provided it by reference).
>
> Here's a way to test it:
>
> <?php
>
> $a = range(0,4);
>
> foreach($a as $k => $v){
> if(isset($a)) unset($a);
> echo "$k => $v<br>";
> }
>
> print_r($a);
>
> ?>
>
> To me it would seem the entire array is copied, since it prints all the
> values even after the array is unset, I got the output:
> 0 => 0
> 1 => 1
> 2 => 2
> 3 => 3
> 4 => 4
>

Rami,

That may be true on the release you're running at. But is it true for
all releases? And will it remain that way? Unless it's documented to
work that way, there's no way of telling.

And these are exactly the types of assumptions which get you in deep
trouble.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация