Bug or undocumented functionality of unset()?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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>';
?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux