简体   繁体   English

打印这样的数组?

[英]printing such array?

How could I print this array var_dump($files); 我如何打印此数组var_dump($files); produces this 产生这个

  array
'Arrow' => 
array
  'Custom' => 
    array
      'original' => 
        array
          ...
      'thumbs' => 
        array
          ...
  'Standard' => 
    array
      'original' => 
        array
          ...
      'thumbs' => 
        array
          ...
'Borders' => 
 array
  'Corners' => 
    array
      'original' => 
        array
          ...
      'thumbs' => 
        array
          ...
  'Embellished Outline' => 
    array
      'original' => 
        array
          ...
      'thumbs' => 
        array
          ...
  'Simple Outline' => 
    array
      'original' => 
        array
          ...
      'thumbs' => 
        array
          ...
  'Solid' => 
    array
      'original' => 
        array
          ...
      'thumbs' => 
        array
          ...
  0 => string 'cannon.gif' (length=10)

i want output like Arrow/Custom/thumbs/053_17_HandLeft.gif 我想要像Arrow / Custom / thumbs / 053_17_HandLeft.gif这样的输出

尝试XDebug ,它将替换var_dump以显示出来,包括语法着色和缩进。

For beautiful lightweight debug, Kint does the job. 对于漂亮的轻量级调试, Kint可以完成工作。 Xdebug is great, but seems a little overkill to install, if only for pretty print or var_dump replacement. Xdebug很棒,但如果仅用于漂亮的打印或var_dump替换,则安装似乎有点过大。

It seems you want to output a list of file paths from some recursive directory structure. 似乎您想从某个递归目录结构中输出文件路径列表。 This function should help: 此功能应有助于:

function createPaths(array $files, $prefix = '') {
    $paths = array();

    foreach ($files as $folder => $file) {
        if (is_array($file)) {
            $subPaths = createPaths($file, $prefix . $folder . '/');
            $paths = array_merge($paths, $subPaths);
        } else {
            $paths[] = $prefix . $file;
        }
    }

    return $paths;
}

$files = array(
    'Corners' => array(
        'original' => array(
            '1.jpg',
            '2.gif',
        ),
    ),
    'foo.jpg'
);

var_dump(createPaths($files));

Try print_r($files); 尝试print_r($files); . Maybe that will expand all arrays. 也许那会扩展所有数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM