getting the variable name in php



I have created a function, it gives more readability compared to the
print_r function. As of print_r, it works both for array or single
variable. I just want to add in it, the opton to view the variable
name for the case of non array variables. Also I want to show the
array name.

Is there any way that the variable name that is passed to the function
can be displayed.

function formattedoutput($object) {

echo "<table style='border:1px #cccccc solid'>";

if(is_array($object)) {
ksort($object);
reset($object);
foreach($object as $f_name=>$f_value) {
echo "<tr><td valign='top'><div align='right'>";
if(!$f_value) { echo "<font color='red'>"; }
echo $f_name;
if(!$f_value) { echo "</font>"; }
echo "&nbsp;:</div></td><td valign='top'><div align='left'>&nbsp;";
if(is_array($f_value)) {
formattedoutput($f_value);
} else {
echo $f_value;
}
echo "</div></td></tr>";
}
} else {
$f_name = ""; // variable name
$f_value = $object;
echo "<tr><td valign='top'><div align='right'>";
if(!$f_value) { echo "<font color='red'>"; }
echo $f_name;
if(!$f_value) { echo "</font>"; }
echo "&nbsp;:</div></td><td valign='top'><div align='left'>&nbsp;";
echo $f_value;
echo "</div></td></tr>";
}

echo "</table>";

}

Thank you.
.