以可读/分层格式显示数组,而不会弄乱路径

时间:2016-02-24 14:15:36

标签: php arrays pretty-print

我有一个数组

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);

VIEW

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

我按照我想要的那样以漂亮的格式显示它,但它有点搞砸了我的

img_path 即可。

我该怎么做?

1 个答案:

答案 0 :(得分:3)

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

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