Calvin Close
asked on
PHP Function to Output Variable Information to Browser or File
I want to write a PHP function that outputs variable information to the browser or a string.
The function must handle single variables and arrays. Currently, I use the following:
echo "\$variable is:<br>";
print_r($variable);
echo "<br>";
I want a function that you can pass the variable to it, and it will do the same.
For example, if $a=23, $b="A string", $c=array(2,3,4), then the function must be able to handle all of these.
OutputVar($var,$return=FAL SE)
{
}
if $return is TRUE, the output is returned as a string. Otherwise, it must output to the browser. The string can then be outputted to a debug file if needed.
Thanks,
Calvin
The function must handle single variables and arrays. Currently, I use the following:
echo "\$variable is:<br>";
print_r($variable);
echo "<br>";
I want a function that you can pass the variable to it, and it will do the same.
For example, if $a=23, $b="A string", $c=array(2,3,4), then the function must be able to handle all of these.
OutputVar($var,$return=FAL
{
}
if $return is TRUE, the output is returned as a string. Otherwise, it must output to the browser. The string can then be outputted to a debug file if needed.
Thanks,
Calvin
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ahhh... micacca's print_r will work better if you have nested arrays.
ASKER
Actually, the above solutions didn't quite answer my question.
if $a = 1, then calling the function OutputVar($a) would output:
$a is:
1
I want the variable name shown, not some general thing like $variable. micacca's solution works except for this point.
if $a = 1, then calling the function OutputVar($a) would output:
$a is:
1
I want the variable name shown, not some general thing like $variable. micacca's solution works except for this point.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.