php print_r nice table

前端 未结 4 729
失恋的感觉
失恋的感觉 2021-02-08 02:46

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?

4条回答
  •  野性不改
    2021-02-08 03:15

    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 '';
        }else{
            echo '';
        }
        $color=0;
        foreach($elem as $k => $v){
            if($max_level%2){
                $rgb=($color++%2)?"#888888":"#BBBBBB";
            }else{
                $rgb=($color++%2)?"#8888BB":"#BBBBFF";
            }
            echo '";
        }
        echo "
    ARRAY
    '; echo 'OBJECT Type: '.get_class($elem).'
    '; echo ''.$k.""; print_nice($v,$max_level,$print_nice_stack); 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); }

    }

提交回复
热议问题