RE: [PHP] Determining the name of a global variable within a func tion

From: Date: Fri, 28 Jul 2000 16:38:38 +0000
Subject: RE: [PHP] Determining the name of a global variable within a func tion
Groups: php.general 
Request: Send a blank email to php-general+get-8812@lists.php.net to get a copy of this message
> I want to write a function that modifies a global array but returns a > different value. Is there any way (in PHP3) to determine the > global name of a variable passed to the function? I had to deal with something like this either earlier this week or late last week. But actually, now that I look at the code, the solution is pretty simple: > for example: > function modify_array($array) { > /* code to modify $array */ > return $someValue; > } > $foo = array("A", "B", "C"); > $bar = modify_array($foo); > /* $foo should now be modified */ You don't need to use a global variable. Just pass your array as such: $bar = modify_array( &$foo ); The '&' operator tells PHP to pass the array by reference and not by value. Chris

« previous php.general (#8812) next »