note 13835 added to function.extract.php

From: Date: Thu, 05 Jul 2001 01:11:17 +0000
Subject: note 13835 added to function.extract.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-14999@lists.php.net to get a copy of this message
Note that the insert symbols are copies and not references of the original array. Here's some sample code to show: $arr['variablex'] = 5; extract($arr); $variablex = 6; print_r($variablex); print_r($arr['variablex']); unset($variablex); reset($arr); list($k,$v) = each($arr); $$k =& $v; $variablex = 7; print_r($variablex); print_r($arr['variablex']); unset($variablex); reset($arr); list($k,$v) = each($arr); $$k =& $arr[$k]; $variablex = 8; print_r($variablex); print_r($arr['variablex']); unset($variablex); reset($arr); list($k,$v) = each($arr); eval('$' . $k . ' =& ' . '$arr[\'' . $k . '\'];'); $variablex = 9; print_r($variablex); print_r($arr['variablex']); This prints out 65758899. What this means is that the first assignment to the newly inserted symbol did not affect the array. It seems to be equivalent to the second snippet ($$k =& $v). Only do the third and the fourth snippets actually create references to the original content. http://www.php.net/manual/en/function.extract.php

« previous php.notes (#14999) next »