I保证这与通常存储到数组.的不同。
我不知道如何命名它的小,关于我的要求!!
第一:对不起英语不好。所以看看下面这个..。
第二:
a. im使用内置服务器: php手工服务
b.框架为Laravel 5.4
我有url http://127.0.0.1:8000/file/999090/img/img-2as
host : 127.0.0.1:8000 etc
main-folder : {/file} Where i store my image
folder-id : {/990909} This is just id for each folder
sub-folder : {/img} Each id has many sub folder [example]
filde-name : {/img2-as} Just file name [example]所以这是个问题:我想在PHP中有这样的数组:
$array = [
0 => '/file',
1 => '/file/990909',
2 => '/file/990909/img',
3 => '/file/990909/img/img-2as'
];发布于 2017-10-24 04:54:23
尝尝这个
$root = '/'; // !!! CHANGE THIS WITH YOUR OWN FOLDER!!!
$iter = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST,
RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied"
);
$paths = array($root);
foreach ($iter as $path => $dir) {
if ($dir->isDir()) {
$paths[] = $path;
}
}
print_r($paths);发布于 2017-10-24 06:39:18
我已经做到这样了:
$parts = "assets/theme/dist/img//img/user2-160x160.jpg";
$path = explode('/', $parts);
for($i=0;$i<count($path);$i++){
for($j=0;$j<$i;$j++){
echo "/".$path[$j];
}
echo "\n";
}其结果是:
/assets
/资产/
/资产/主题/区域
/资产/主题/dist/img
/资产/主题/dist/img/
/资产/主题/dist/img/img
这是我想要的数组,我已经尝试使用array_push,但结果更糟。
发布于 2017-10-24 09:18:57
我已经找到了。只需复制到您的php文件。
$path = "assets/adminlte/dist/img/user2-160x160";
$asd = explode( '/', $path );
$num = count($asd)-1;
$arr = [];
for($i=0;$i<count($asd);$i++) {
for($j=0;$j<=$i;$j++){
@$arr[$i] .= "/".$asd[$j];
}
}
echo "\n";
print_r($arr);https://stackoverflow.com/questions/46902429
复制相似问题