Reply to Bug or undocumented functionality of unset()?

Your name:

Reply:


Posted by karl on 02/23/05 08:07

Hi All,

Does unset() create a copy of the array and then overwrite the
original
somehow
destroying the reference?
In the example below, no item has it's value set to 'foo', however if
the
$stuff array is
accessed directly (see commented line) rather than by reference it
works
fine. In
addition to this, if the unset(); line is commented, the reference
will
also work.

Anyone know why?

Thanks,

Karl.
-----------------------------------------------
<?php
$stuff = array(array('one','two'),
array('one','two'),
array('three','four'),
array('five','six'),
array('seven','eight'),
array('nine','ten'));

print '<pre>'; print_r($stuff); print '</pre>';

foreach ($stuff as $key => &$values) {
print "on key:$key<br>";
if(($key%2)==0){
print "Running unset for $key <br>";
unset ($stuff[$key]);
}else{
print "Running change for $key <br>";
$values[1]='foo';
// $stuff[$key][1] = 'foo';
}
}
print '<pre>'; print_r($stuff); print '</pre>';
?>

[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

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