RE: [PHP] finding a variables name
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:[EMAIL PROTECTED]] Sent: Tuesday, May 15, 2001 6:45 AM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] finding a variables name
Hey ppl, How does one find the name of a variable, not what the variable contains? This is not the same as variable variables. I know this seems a bit pointless but I have come across a situation where I really need to be able to do this. Hope someone can help, Thanks, Joseph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] finding a variables name
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Joseph Blythe) wrote: How does one find the name of a variable, not what the variable contains? This is not the same as variable variables. I know this seems a bit pointless but I have come across a situation where I really need to be able to do this. Can you give an example of code in which you'd be doing this? (Seeing how you plan to access the variable of indeterminate name would help in suggesting a solution. For example, if it is known to be an array member, you might be able to use key()..., etc.) -- CC -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] finding a variables name
foreach($GLOBALS as $key=$val) echo $key=$valbr\n; see the list() and each() functions in the manual for php3 - Original Message - From: Joseph Blythe [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, May 15, 2001 1:48 PM Subject: [PHP] finding a variables name Hey ppl, How does one find the name of a variable, not what the variable contains? This is not the same as variable variables. I know this seems a bit pointless but I have come across a situation where I really need to be able to do this. Hope someone can help, Thanks, Joseph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] finding a variables name
CC Zona wrote: Can you give an example of code in which you'd be doing this? 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]