RE: [PHP] rename variables

From: Date: Wed, 24 Sep 2003 20:44:09 +0000
Subject: RE: [PHP] rename variables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-163813@lists.php.net to get a copy of this message
> I'm trying to rename some variables. > > first I have a function - > randomize (3,4); //has created unique $numbers > > then I want to create a function for the renaming: > > renameit($sculp); //sends $sculp for the new variable name > > and this function (and variations) > > function renameit($var){ > $z = 1; > foreach ($numbers as $currNum){ > $var[$z++] = $output[$currNum]; //creates $sculp[1 and 2] > } > } > > but failed > > if I use > $z = 1; > foreach ($numbers as $currNum){ > $sculp[$z++] = $output[$currNum]; > > after randomize (3,4); > > it works fine -but I want it in a function. > > Any suggestions? Read up on scope. If you want $numbers to be available to your function it has to be in that function's scope. Either pass it or declare it global. http://us2.php.net/variables.scope

« previous php.general (#163813) next »