RE: [PHP] finding a variables name
| From: | Eetay Natan | Date: | Tue, 15 May 2001 10:13:11 +0000 |
| Subject: | RE: [PHP] finding a variables name | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-52818@lists.php.net to get a copy of this message | ||
Hello.
you can try passing the name of the variable? i.e.:
function makeJSArray($array_name) {
global $$array_name
$array = $$array_name;
...
...
}
otherwise, I don't think you can logically access the name. Consider this:
$a=array(...);
$b = &a;
makeJSArray( $b );
What name will you get, 'a' or 'b' ?
Regards,
Eetay
-----Original Message-----
From: Joseph Blythe [mailto:joe.blythe@binarylogic.com.au]
Sent: Tuesday, May 15, 2001 6:45 AM
To: php-general@lists.php.net
Cc: php-general@lists.php.net
Subject: Re: [PHP] finding a variables name
Joseph Blythe wrote:
> Ok here is what I am trying to acheive, basically turning a php array
> into a javascript array, note this is untested and most likley won't
> work :-)
>
> Where $array_name I need the same name as the functions first and only
> argument $array, so I need the name of the array that has been passed
> to the function.
>
> ///////////////////////////////////////////////////
>
> function makeJSArray($array) {
>
> $out = "$array_name = new Array(";
>
> $size = sizeof($array);
> $i = 0;
> while ( list($key, $val) = each($array) ) {
>
> $out .= "$array_name[$key] = $val";
>
> if ($size != $i - 1)
> $out .= ",";
> }
>
> $out .= ");";
> return $out;
> }
>
> /////////////////////////////////////////////////
>
> Thanks,
>
> Joseph
He he, would also help if I closed my while loop and added the increment
for $i
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net