I\'m looking to be able to produce a nicely formatted table with rows and columns from the contents of a print_r array statement?
Any ideas?
Here is another nice example that I found. Same output, longer code, little bit more color.
function print_nice($elem,$max_level=10,$print_nice_stack=array()){
if(is_array($elem) || is_object($elem)){
if(in_array(&$elem,$print_nice_stack,true)){
echo "RECURSION";
return;
}
$print_nice_stack[]=&$elem;
if($max_level<1){
echo "nivel maximo alcanzado";
return;
}
$max_level--;
echo "";
if(is_array($elem)){
echo 'ARRAY ';
}else{
echo '';
echo 'OBJECT Type: '.get_class($elem).' ';
}
$color=0;
foreach($elem as $k => $v){
if($max_level%2){
$rgb=($color++%2)?"#888888":"#BBBBBB";
}else{
$rgb=($color++%2)?"#8888BB":"#BBBBFF";
}
echo '';
echo ''.$k." ";
print_nice($v,$max_level,$print_nice_stack);
echo " ";
}
echo "
";
return;
}
if($elem === null){
echo "NULL";
}elseif($elem === 0){
echo "0";
}elseif($elem === true){
echo "TRUE";
}elseif($elem === false){
echo "FALSE";
}elseif($elem === ""){
echo "EMPTY STRING";
}else{
echo str_replace("\n","*
\n",$elem);
}
}