请问如下代码中
$pagearr["name"]=$_name;
$pagearr["size"]=$_size;
$pagearr["time"]=$_time;
怎么通过foreach 取$pagearr的值呢?
我要循环到一个表格里面去、弄了两天啦
function page($f,$pagesize,$current)
{
$_name = array();
$_size = array();
$_time = array();
$total = ceil(count($f)/$pagesize);
$prev = (($current-1)<=0 ? "1":($current-1));
$next =($current+1>=$total ? $total:$current+1);
$current =($current>($total) ? ($total):$current);
$start = ($current-1)*$pagesize;
for($i=$start;$i<($start+$pagesize);$i++)
{
if ($f!="." && $f!="..")
{
$t = array_map('filemtime',$f);
$s = array_map('filesize',$f);
array_multisort($t,SORT_DESC,$f);
}
array_push($_name,$f[$i]);
array_push($_size,$s[$i]);
array_push($_time,$t[$i]);
}
$pagearr["name"]=$_name;
$pagearr["size"]=$_size;
$pagearr["time"]=$_time;
$pagearr["page"]="<a href=\"?acticon=barfilelist&id=".$_GET['id']."&page=1\">first</a> <a href=\"?acticon=barfilelist&id=".$_GET['id']."&page={$prev}\">prev</a> <a href=\"?acticon=barfilelist&id=".$_GET['id']."&page={$next}\">next</a> <a href=\"?acticon=barfilelist&id=".$_GET['id']."&page={$total}\">end</a>";
return $pagearr;
}if ($handle = opendir('.\dbbak'))
{ echo '<ul><b><li style="margin-top:20px;text-decoration:none;">客户列表:</b>
<hr width=80% size=3 color=#0099ff style="FILTER:alpha(opacity=100,finishopacity=0,style=1)">
<ul>';
while ($file = readdir($handle)) {
if ($file!='.' && $file!="..")
echo '<li><a target="select_result" href=readir.php?acticon=barfilelist&id='.$file.'>'.$file.'</a></li>';
}
echo '</ul>
</li>
</ul>';
closedir($handle);
}
break;case('barfilelist'):
$patch='./dbbak/';
if ($handle = opendir($patch.$_GET['id']))
{
echo '<table id="tb1">
<th width="80px">客户编号</th>
<th width="200px">文件名</th>
<th width="80px">文件大小</th>
<th width="200px;">上传时间</th>
<th width="30px">下载</th>
</table>';
}
$f = array();
$f = glob($patch.$_GET['id'].'/*');
if (isset($_GET['page']))
{
$page = $_GET['page'];
}
else
{
$page = 1;
}
$r = page($f,20,$page);
foreach($r["name"] as $value){
echo '<table id="tb2">
<td width="80px">'.$_GET['id'].'</td>
<td width="200px">'.substr($value,19).'</td>
<td width="80px">KB</td>
<td width="200px"></td>
<td width="30px"><a href="http://localhost/'.$value.'"><img alt="点击下载" align="center" style="border:0;" src="./image/download2.gif" /></a></td>
</table>';
}
echo '<div style="text-align:center;margin-top:25px;">
'.$r["page"].'
</div>';
$pagearr["name"]=$_name;
$pagearr["size"]=$_size;
$pagearr["time"]=$_time;
怎么通过foreach 取$pagearr的值呢?
我要循环到一个表格里面去、弄了两天啦
function page($f,$pagesize,$current)
{
$_name = array();
$_size = array();
$_time = array();
$total = ceil(count($f)/$pagesize);
$prev = (($current-1)<=0 ? "1":($current-1));
$next =($current+1>=$total ? $total:$current+1);
$current =($current>($total) ? ($total):$current);
$start = ($current-1)*$pagesize;
for($i=$start;$i<($start+$pagesize);$i++)
{
if ($f!="." && $f!="..")
{
$t = array_map('filemtime',$f);
$s = array_map('filesize',$f);
array_multisort($t,SORT_DESC,$f);
}
array_push($_name,$f[$i]);
array_push($_size,$s[$i]);
array_push($_time,$t[$i]);
}
$pagearr["name"]=$_name;
$pagearr["size"]=$_size;
$pagearr["time"]=$_time;
$pagearr["page"]="<a href=\"?acticon=barfilelist&id=".$_GET['id']."&page=1\">first</a> <a href=\"?acticon=barfilelist&id=".$_GET['id']."&page={$prev}\">prev</a> <a href=\"?acticon=barfilelist&id=".$_GET['id']."&page={$next}\">next</a> <a href=\"?acticon=barfilelist&id=".$_GET['id']."&page={$total}\">end</a>";
return $pagearr;
}if ($handle = opendir('.\dbbak'))
{ echo '<ul><b><li style="margin-top:20px;text-decoration:none;">客户列表:</b>
<hr width=80% size=3 color=#0099ff style="FILTER:alpha(opacity=100,finishopacity=0,style=1)">
<ul>';
while ($file = readdir($handle)) {
if ($file!='.' && $file!="..")
echo '<li><a target="select_result" href=readir.php?acticon=barfilelist&id='.$file.'>'.$file.'</a></li>';
}
echo '</ul>
</li>
</ul>';
closedir($handle);
}
break;case('barfilelist'):
$patch='./dbbak/';
if ($handle = opendir($patch.$_GET['id']))
{
echo '<table id="tb1">
<th width="80px">客户编号</th>
<th width="200px">文件名</th>
<th width="80px">文件大小</th>
<th width="200px;">上传时间</th>
<th width="30px">下载</th>
</table>';
}
$f = array();
$f = glob($patch.$_GET['id'].'/*');
if (isset($_GET['page']))
{
$page = $_GET['page'];
}
else
{
$page = 1;
}
$r = page($f,20,$page);
foreach($r["name"] as $value){
echo '<table id="tb2">
<td width="80px">'.$_GET['id'].'</td>
<td width="200px">'.substr($value,19).'</td>
<td width="80px">KB</td>
<td width="200px"></td>
<td width="30px"><a href="http://localhost/'.$value.'"><img alt="点击下载" align="center" style="border:0;" src="./image/download2.gif" /></a></td>
</table>';
}
echo '<div style="text-align:center;margin-top:25px;">
'.$r["page"].'
</div>';
$pagearr["size"] = $_size;
$pagearr["time"] = $_time;echo "<table>\n<tr>\n";foreach($pagearr as $k => $v) echo "<td>{$k}:{$v}</td>\n";echo "</tr>\n</table>\n";
$pagearr["name"] = array('AAA', 'BBB', 'CCC');
$pagearr["size"] = array('111', '222', '333');
$pagearr["time"] = array('@@@', '###', '$$$');echo "<table>\n";foreach($pagearr as $k => $v) {
echo "<tr>\n";
for($i = 0; $i < count($v); $i ++) echo "<td>{$v[$i]}</td>\n";
echo "</tr>\n";
echo "<tr><td>{$v[2]}</td><td>{$v[1]}</td><td>{$v[0]}</td></tr>\n";
echo "<tr>\n";
foreach($v as $w) echo "<td>{$w}</td>\n";
echo "</tr>\n";
}echo "</table>\n";
CCC BBB AAA
AAA BBB CCC
111 222 333
333 222 111
111 222 333
@@@ ### $$$
$$$ ### @@@
@@@ ### $$$
但是需要的结果应该是文件名 文件大小 访问时间
AAA 111 @@@
BBB 222 333
@@@ ### SSS
$pagearr["name"] = array('AAA', 'BBB', 'CCC');
$pagearr["size"] = array('111', '222', '333');
$pagearr["time"] = array('@@@', '###', '$$$');echo "<table>\n";
echo "<tr><td>文件名</td><td>文件大小</td><td>访问时间</td></tr>\n";for($i = 0; $i < 3; $i ++) echo "<tr><td>{$pagearr['name'][$i]}</td><td>{$pagearr['size'][$i]}</td><td>{$pagearr['time'][$i]}</td></tr>\n";echo "</table>\n";