Improving my print_r Algorithm
Well guys, it's a simple question (more than a question i'ts a challenge).
When i develop large applications its really hard to track how the arrays are working (in arrays of more than 3 dimensions, or arrays that contain arrays that contain arrays, etc...)
So, the PHP developers have the print_r($array) function. The format that this deliver the information its helpful if your array is no longer than 1 dimension or a couple of variables... so, i programmed a little function that parses arrays (and arrays of arrays) using a little of CSS and HTML.
I'll share the function for you, but more important than that, is to improve it, to make it more friendly (avoid use images or that... just a simple function that dont user other files to work with), or if there's something (a library or a function) that i don't know that help in this matter?
Thanks in advance.
The function:
function print_a($array,$prefix = "")
{
if(is_array($array))
{
foreach($array as $value => $valor)
{
echo "<tr>";
echo " <td>";
if(is_array($valor))
开发者_Go百科 {
echo "<div style='background-color: #C7E792;height: 5px; width: 100%; padding: 5px;'><strong>ARRAY: $value</strong></div>";
echo $prefix." ";
print_a($valor,$prefix." > ");
}
else
{
if(!is_numeric($value))
{
echo "<div style='background-color: #FFFFFF;height: 10px; width: 100%;'>";
echo $prefix;
echo "<b>".$value."</b> = ".$valor."<br/>";
echo "</div>";
}
}
}
} else { echo "It's not an array =( !"; }
}
I would recomment using Krumo. Krumo does all you want and more.
I would recommend trying http://www.xdebug.org/. You can customize the depth and style of your var_dump
and print_r
output.
精彩评论