justravis Posted September 4, 2007 Share Posted September 4, 2007 In this simple example, I would like the function to output, the name of the var, the letter 'x' <?php function out($var) { echo "$var<br />"; #echo $$var; #echo func_get_args($var); #$varlist=get_defined_vars(); #echo $varlist[0]; } $x=3; out($x); ?> Any ideas? Thanks for yr time! Link to comment https://forums.phpfreaks.com/topic/67866-php-name-of-variable-being-passed/ Share on other sites More sharing options...
Jessica Posted September 4, 2007 Share Posted September 4, 2007 Uhm, it will always be "var". It is not x, because out takes the argument $var, not $x. Link to comment https://forums.phpfreaks.com/topic/67866-php-name-of-variable-being-passed/#findComment-341148 Share on other sites More sharing options...
gerkintrigg Posted September 4, 2007 Share Posted September 4, 2007 you could possibly do something with a FOR loop to get the name of the variable AND the name of the value. Link to comment https://forums.phpfreaks.com/topic/67866-php-name-of-variable-being-passed/#findComment-341194 Share on other sites More sharing options...
ToonMariner Posted September 4, 2007 Share Posted September 4, 2007 think you may have to use variable variables here. <?php function out($varname, $varavl) { echo "$varname = $varval<br />"; } $x = 'x'; $$x=3; out($x,$$x); ?> Link to comment https://forums.phpfreaks.com/topic/67866-php-name-of-variable-being-passed/#findComment-341203 Share on other sites More sharing options...
justravis Posted September 4, 2007 Author Share Posted September 4, 2007 since the function cant even tell the name of the var being passed to it, how would a for loop inside the function make a difference? THANK YOU. Link to comment https://forums.phpfreaks.com/topic/67866-php-name-of-variable-being-passed/#findComment-341485 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.