You are here: Re: safe to delete elements of array in foreach « PHP Programming Language « IT news, forums, messages
Re: safe to delete elements of array in foreach

Posted by Rami Elomaa on 05/21/07 16:00

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.Elomaa@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze

 

Navigation:

[Reply to this 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

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