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! Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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); ?> Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.