Re: How to print variable name and contents

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux