开发者

How can I format (pretty print) a multi-dimensional array for debugging? [duplicate]

开发者 https://www.devze.com 2023-02-09 06:59 出处:网络
This question already has answers here: Make var_dump look pretty [duplicate] (16 answers) Closed 1 year ago.
This question already has answers here: Make var_dump look pretty [duplicate] (16 answers) Closed 1 year ago.

I've seen some online pretty print modules for code. Anyone know of one that will format a multi-dimensional array into readable display?

Example, translate this:

array(83) { [0]=> array(2) { ["name"]=> string(11) "CE2 Options" ["type"]=> string(5) "title" } [1]=> array(1) { ["type"]=> string(4) "open" } [2]=> array(5) { ["name"]=> string(8) "Template" ["desc"]=> string(638) "test description" ["id"]=> string(9) "my_theme" ["type"]=> string(14) "selectTemplate" ["options"]=> array(13) {

Into this...

array(83) { 
    [0]=> array(2) { ["name"]=> string(11) "My Options" ["type"]=> string(5) "title" } 
    [1]=> array(1) { ["type"]=> string(4) "open" } 
    [2]=> array(5) { 
        ["name"]=> string(8) "Template"开发者_JAVA百科 
        ["desc"]=> string(638) "Test description" 
        ["id"]=> string(9) "my_theme" 
        ["type"]=> string(14) "selectTemplate" 
        ["options"]=> array(13) { 
            [0]=> string(10) "test" 


If you are dumping it to HTML document use the

<pre></pre>

it does exactly that.


If you want a nicer output than var_dump , then check out the alternatives listed here:
A more pretty/informative Var_dump alternative in PHP?

Particularily http://krumo.sourceforge.net/ provides a much more accessible DHTML view for variable dumps. (It requires an extra include() though.)

And if you actually want to keep the generated output as static html, you might have to write a smallish wrapper script.


the pretty version is just what you get when you have XDebug installed and html_errors is set to On. Then you use var_dump($array). And make sure you set children and depth to what you need. there you go

0

精彩评论

暂无评论...
验证码 换一张
取 消