【问题标题】:Display an array in a readable/hierarchical format without mess up the path以可读/分层格式显示数组而不会弄乱路径
【发布时间】:2016-06-06 21:14:34
【问题描述】:

我有一个数组

array:10 [▼
  0 => array:3 [▼
    "name" => "Xperia Z Ultra"
    "img" => "xperia-z-ultra.jpg"
    "img_path" => "/Applications/MAMP/htdocs/code/site/public/images/photos/devices/"
  ]
  1 => array:3 [▶]
  2 => array:3 [▶]
  3 => array:3 [▶]
  4 => array:3 [▶]
  5 => array:3 [▶]
  6 => array:3 [▶]
  7 => array:3 [▶]
  8 => array:3 [▶]
  9 => array:3 [▶]

]

我想让它漂亮所以我做了这个

$pretty_devices = json_encode($devices, JSON_PRETTY_PRINT);

查看

<div><pre>{{$pretty_devices}}</pre></div>

我得到了它以我想要的漂亮格式显示,但它有点搞砸了我的

img_path

我该如何阻止它?

【问题讨论】:

  • $pretty_devices = json_encode($devices, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES); 如果您遇到的唯一问题是转义的反斜杠...有许多与格式相关的 JSON 常量。 JSON_PRETTY_PRINTJSON_UNESCAPED_SLASHES 是位掩码(值 128 和 64),因此将它们与按位 | 运算符结合起来将结合两者
  • 哇,这太棒了。

标签: php arrays pretty-print


【解决方案1】:

如果您只想很好地看到它,请尝试使用 print_r()。

echo "<div><pre>".print_r($pretty_devices, true)."</pre></div>"

【讨论】:

    猜你喜欢
    • 2011-07-20
    • 1970-01-01
    • 2016-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多