我有一个创建数组的for循环,如何在一个主数组中合并所有数组
for ($i = 1; $i <= 10; $i++)
{
$dirname = substr( $ring['ringPicDir'] ,0, -4 );
$lastpart = basename( $dirname , ".zip");
$abspath = substr( $dirname ,strpos( $dirname, "com/")+4 );
$direcotypath = "../".$abspath."/".$lastpart;
$files = glob($direcotypath."/*.*");
foreach ($files as $key => &$value)
{
$value = str_replace( "..", $url, $value);
}
$mainFiles = $mainFiles + $files;// Something like this??
}
答案 0 :(得分:1)
好吧,你可以试试这段代码:
$mainFiles = array();
for ($i = 1; $i <= 10; $i++) {
$dirname = substr( $ring['ringPicDir'] ,0, -4 );
$lastpart = basename( $dirname , ".zip");
$abspath = substr( $dirname ,strpos( $dirname, "com/")+4 );
$direcotypath = "../".$abspath."/".$lastpart;
$files = glob($direcotypath."/*.*");
foreach ($files as $key => &$value) {
$value = str_replace( "..", $url, $value);
}
$mainFiles[] = $files;
}
所以用$ mainFiles显示文件数组,
echo $mainFiles[0]['key name here'];