madrazel Posted April 24, 2007 Share Posted April 24, 2007 like this: $f = "bang"; function listvars() { $args = func_get_args(); foreach ($args as $val) { echo $val."\n"; }; }; listvars($f,$f); gives output: bang bang how to make it display: $f $f Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted April 24, 2007 Share Posted April 24, 2007 listvars('$f','$f'); hahah ;D whay would you want to? Pass in the pointer to $f if you want to change it: <?php function xx( &$t ) { $t++; } $t = 0; xx( $t ); echo $t; ?> See how this echos '1', the function xx has modified the variable $t because we passed a pointer to the function (the & means 'pointer to') monk.e.boy Quote Link to comment Share on other sites More sharing options...
madrazel Posted April 24, 2007 Author Share Posted April 24, 2007 actually i got something like this in mind: $c = 'bang'; $f = 'c'; echo $$f."\n"; an now I'm struggling to make function with it, that will help me with debugging scripts Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted April 24, 2007 Share Posted April 24, 2007 Have a look at var_dump. But I can't see what finding out the name of the variable would do for you. Say we have a function called 'get_name' that would do what you want: $a = 'boo'; echo get_name( $a ) .' = '. $a; How is this better than just doing: $a = 'boo'; echo '$a = '. $a; ? Eh? Madness. For amazing debugging try getting NuSphere, PHPEd. It's brilliant. monk.e.boy Quote Link to comment Share on other sites More sharing options...
madrazel Posted April 25, 2007 Author Share Posted April 25, 2007 whatever, i done this: function listvars($x) { $args = explode(',',$x); ob_start(); foreach ($args as $val) { global $$val; echo '$'.$val.' = '; if (is_null($$val)) { echo "NULL"; } elseif ($$val === FALSE) { echo "FALSE"; } elseif ($$val === TRUE) { echo "TRUE"; } elseif ($$val === '') { echo "EMPTY"; } elseif (is_array($$val)) { print_r($$val);} else { echo $$val; }; echo "\n"; }; echo "<pre>\n".ob_get_clean()."</pre>\n"; }; $a="t"; $b=''; $c="h"; listvars("a,b,c"); 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.