Make var_dump look pretty

后端 未结 14 2507
忘掉有多难
忘掉有多难 2020-12-02 04:23

I have a simple $_GET[] query var set for showing testing data when pulling down queries from the DB.


  <         


        
14条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 04:33

    Here is my function to have a pretty var_dump. Combined with Xdebug, it helps a lot to have a better view of what we are dumping.

    I improved a bit the display of Xdebug (give some space around, separator between values, wrap long variables, etc).

    When you call the function, you can set a title, a background, a text color to distinguish all your var_dump in a page.

    Or not ;)

    /**
     * Pretty var_dump 
     * Possibility to set a title, a background-color and a text color
     */ 
    function dump($data, $title="", $background="#EEEEEE", $color="#000000"){
    
        //=== Style  
        echo "  
        
        ";
    
        //=== Content            
        echo "
    ";
        echo    "

    $title

    "; var_dump($data); echo "
    "; }

提交回复
热议问题