Re: rename variables
| From: | Dan J. Rychlik | Date: | Wed, 24 Sep 2003 20:49:30 +0000 |
| Subject: | Re: rename variables | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-163814@lists.php.net to get a copy of this message | ||
Global works...
----- Original Message -----
From: "Jennifer Goodie" <goodie@apollointeractive.com>
To: "Boyd Pearson" <boyd@eldritchdark.com>; <php-general@lists.php.net>
Sent: Wednesday, September 24, 2003 3:44 PM
Subject: RE: [PHP] rename variables
> > 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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>