Re: How to print variable name and contents

From: Date: Thu, 16 Jun 2005 01:42:37 +0000
Subject: Re: How to print variable name and contents
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-217046@lists.php.net to get a copy of this message
Hello, Wednesday, June 15, 2005, 2:33:48 PM, you wrote: ncn> I want to write a trace procedure and call it with variable ncn> names, and I am having trouble with the syntax. My goal is to ncn> have a procedure that will echo lines such as: ncn> Trace: $myvar="the contents of $myvar ncn> My attempt that didn't work is to write a function: ncn> function my_trace($m){ ncn> echo ("\n<br>TRACE: $m = "); ncn> eval("\$t=\"$m\";"); ncn> echo($t."<br>\n"); ncn> } Here's one way: function my_trace ($varname, $varvalue) { $varvalue = print_r($varvalue, true); echo "TRACE: $varname = \"$varvalue\"<br />"; } my_trace("\$my_var", $my_var); Another might be to look at the var_dump and var_export functions. Best regards, Richard Davey -- http://www.launchcode.co.uk - PHP Development Services "I do not fear computers. I fear the lack of them." - Isaac Asimov

« previous php.general (#217046) next »