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:1 px #cccccc solid'>";
if(is_array($ob ject)) {
ksort($object);
reset($object);
foreach($object as $f_name=>$f_val ue) {
echo "<tr><td valign='top'><d iv align='right'>" ;
if(!$f_value) { echo "<font color='red'>"; }
echo $f_name;
if(!$f_value) { echo "</font>"; }
echo " :</div></td><td valign='top'><d iv align='left'>&n bsp;";
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'><d iv align='right'>" ;
if(!$f_value) { echo "<font color='red'>"; }
echo $f_name;
if(!$f_value) { echo "</font>"; }
echo " :</div></td><td valign='top'><d iv align='left'>&n bsp;";
echo $f_value;
echo "</div></td></tr>";
}
echo "</table>";
}
Thank you.
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:1 px #cccccc solid'>";
if(is_array($ob ject)) {
ksort($object);
reset($object);
foreach($object as $f_name=>$f_val ue) {
echo "<tr><td valign='top'><d iv align='right'>" ;
if(!$f_value) { echo "<font color='red'>"; }
echo $f_name;
if(!$f_value) { echo "</font>"; }
echo " :</div></td><td valign='top'><d iv align='left'>&n bsp;";
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'><d iv align='right'>" ;
if(!$f_value) { echo "<font color='red'>"; }
echo $f_name;
if(!$f_value) { echo "</font>"; }
echo " :</div></td><td valign='top'><d iv align='left'>&n bsp;";
echo $f_value;
echo "</div></td></tr>";
}
echo "</table>";
}
Thank you.
Comment