getting the variable name in php
- From: yehaimanish@xxxxxxxxx (manish)
- Date: 2 Jun 2005 04:39:33 -0700
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 " :</div></td><td valign='top'><div align='left'> ";
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 " :</div></td><td valign='top'><div align='left'> ";
echo $f_value;
echo "</div></td></tr>";
}
echo "</table>";
}
Thank you.
.
- Follow-Ups:
- Re: getting the variable name in php
- From: Forcey Li
- Re: getting the variable name in php
- Prev by Date: Re: Calendar import/export
- Next by Date: Set text on picture
- Previous by thread: Re: Calendar import/export
- Next by thread: Re: getting the variable name in php
- Index(es):