0
我有非常复杂的数组,我想为HTML创建获取值。如何从PHP中的复杂多维数组中获取值并将它们转换为字符串
我在我的数组中有目录中的jpg文件列表,但我希望所有来自'materialy-do-plis'目录的文件都有文件的子目录,有时甚至更多的子目录有更多的文件。
我想在foreach数组中获得一个很好生成的URL,并在目录名和文件末尾。
这是我的数组怎么样子:https://paste.ofcode.org/vE7qBXvGZNDGMSenF9ijST(超长)
这是我的代码得到它,如果这能帮助:
function pathToArray($path , $separator = '/') {
if (($pos = strpos($path, $separator)) === false) {
return array($path);
}
return array(substr($path, 0, $pos) => pathToArray(substr($path, $pos + 1)));
}
$dir = APPPATH.'../media/multimedia/obrazy/materialy-do-plis/';
$results = array();
if (is_dir($dir)) {
$iterator = new RecursiveDirectoryIterator($dir);
foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) {
if ($file->isFile()) {
$thispath = str_replace('\\', '/', $file);
$thisfile = utf8_encode($file->getFilename());
$results = array_merge_recursive($results, pathToArray($thispath));
}
}
}
echo "<pre>";
print_r($results);
array_walk($products, function ($value, $key) use ($stores, &$array) {
$array[$value['store']][] = $value['product'];
});
print_r($array);
我会尝试一下,谢谢。 – Aksebkit