如何格式化(漂亮打印)多维数组以进行调试?
我见过一些在线漂亮的代码打印模块。有人知道可以将多维数组格式化为可读的显示吗?
例如,翻译一下:
数组(83) { [0]=>;数组(2){ [“姓名”]=>字符串(11)“CE2 选项” [“类型”]=> string(5) "标题" } [1]=> 数组(1){ [“类型”] =>字符串(4)“打开” [2] =>数组(5){ [“名称”] => string(8) "模板" ["desc"]=> string(638)“测试描述” [“id”]=>字符串(9)“我的主题” [“类型”]=>字符串(14)“选择模板” [“选项”] =>数组(13){
到这个...
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"
["desc"]=> string(638) "Test description"
["id"]=> string(9) "my_theme"
["type"]=> string(14) "selectTemplate"
["options"]=> array(13) {
[0]=> string(10) "test"
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"
["desc"]=> string(638) "Test description"
["id"]=> string(9) "my_theme"
["type"]=> string(14) "selectTemplate"
["options"]=> array(13) {
[0]=> string(10) "test"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您将其转储到 HTML 文档,请使用它,
它正是这样做的。
If you are dumping it to HTML document use the
it does exactly that.
如果您想要比 var_dump 更好的输出,请查看此处列出的替代方案:
PHP 中更漂亮/信息更丰富的 Var_dump 替代方案?
特别是 http://krumo.sourceforge.net/ 为变量转储提供了更易于访问的 DHTML 视图。 (不过它需要额外的 include() 。)
如果您确实希望将生成的输出保留为静态 html,您可能需要编写一个较小的包装脚本。
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.
当您安装了 XDebug 并且 html_errors 设置为 On 时,您会得到漂亮的版本。然后使用 var_dump($array)。并确保您根据需要设置子项和深度。 就这样
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