|
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>';
?>
Navigation:
[Reply to this message]
|