Making PHP var_dump() values display one line per value

前端 未结 14 1229
隐瞒了意图╮
隐瞒了意图╮ 2020-12-23 15:41

When I echo var_dump($_variable), I get one long, wrapping line with all varable\'s and values like

[\"kt_login_user\"]=>  string(8) \"teacher1\" [\"kt_lo         


        
相关标签:
14条回答
  • 2020-12-23 16:45

    For me the right answer was

    echo '<pre>' . var_export($var, true) . '</pre>';
    

    Since var_dump($var) and var_export($var) do not return a string, you have to use var_export($var, true) to force var_export to return the result as a value.

    0 讨论(0)
  • 2020-12-23 16:47

    I usually have a nice function to handle output of an array, just to pretty it up a bit when debugging.

    function pr($data)
    {
        echo "<pre>";
        print_r($data); // or var_dump($data);
        echo "</pre>";
    }
    

    Then just call it

    pr($array);
    

    Or if you have an editor like that saves snippets so you can access them quicker instead of creating a function for each project you build or each page that requires just a quick test.

    For print_r:

    echo "<pre>", print_r($data, 1), "</pre>";
    

    For var_dump():

    echo "<pre>", var_dump($data), "</pre>";
    

    I use the above with PHP Storm. I have set it as a pr tab command.

    0 讨论(0)
提交回复
热议问题