我创建了一个非常简单的文件目录,根据传递给它的目录URL显示来自公共html外部的文件,即/home/peter/root_storage/folder_1/folder_2/folder_3
我需要能够从传递的相同字符串创建面包屑,并在数组中输出如下所示:
array(
array(
name => 'root_storage',
url => '/home/peter/root_storage'
),
array(
name => 'folder_1',
url => '/home/peter/root_storage/folder_1'
),
array(
name => 'folder_2',
url => '/home/peter/root_storage/folder_1/folder_2'
),
array(
name => 'folder_3',
url => '/home/peter/root_storage/folder_1/folder_2/folder_3'
)
)
任何方向都会受到赞赏。
答案 0 :(得分:1)
不确定这是否是您的意思:
$str = '/home/peter/root_storage/folder_1/folder_2/folder_3';
$all = array_filter(explode('/',$str));
$accume = '';
$i = 0;
foreach($all as $dir) {
$accume .= $dir.'/';
$new[$i][] = $dir;
$new[$i][] = $accume;
$i++;
}
print_r($new);
给你:
Array
(
[0] => Array
(
[0] => home
[1] => home/
)
[1] => Array
(
[0] => peter
[1] => home/peter/
)
[2] => Array
(
[0] => root_storage
[1] => home/peter/root_storage/
)
[3] => Array
(
[0] => folder_1
[1] => home/peter/root_storage/folder_1/
)
[4] => Array
(
[0] => folder_2
[1] => home/peter/root_storage/folder_1/folder_2/
)
[5] => Array
(
[0] => folder_3
[1] => home/peter/root_storage/folder_1/folder_2/folder_3/
)