function GetImages($orderByDate, $start, $end)
{
$container = array();
if ($handle = opendir('uploads'))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$filename = 'uploads/' . $file;
$lastEdit = date("F d Y H:i:s.", filemtime($filename));
$image = array(
'fileName' => $file,
'lastEdit' => $lastEdit
);
array_push($container, $image);
}
}
closedir($handle);
}
if($orderByDate)
{
function date_compare($a, $b)
{
$t1 = strtotime($a['lastEdit']);
$t2 = strtotime($b['lastEdit']);
return $t1 - $t2;
}
usort($container, 'date_compare');
}
if(isset($start) && isset($end))
{
array_slice($container, $start, $end);
}
return $container;
}
echo '<pre>';
var_dump(GetImages(true, 0, 5));
echo '</pre>';
isnt slice
要走這裏的路嗎?即使我傳遞了開始和結束值,我仍然從數組中獲取所有記錄。由於return array range
你會想把'array_slice(...)'行分配給一些變量,像這樣:'$ result = array_slice(...);' – summea 2012-04-24 22:08:42