费了一段时间,总算完成这个作业,也算是一种锻炼吧,以下是代码,虽然感觉效率比较低,为什么不用数据库呢?
header('Content-type:text/html;charset=utf-8');
//2维数组排序
function sysSortArray($ArrayData, $KeyName1, $SortOrder1 = "SORT_ASC", $SortType1 = "SORT_REGULAR")
{
if (!is_array($ArrayData)) {
return $ArrayData;
}
// Get args number.
$ArgCount = func_num_args();
// Get keys to sort by and put them to SortRule array.
for ($I = 1; $I < $ArgCount; $I++) {
$Arg = func_get_arg($I);
if (!eregi("SORT", $Arg)) {
$KeyNameList[] = $Arg;
$SortRule[] = '$' . $Arg;
} else {
$SortRule[] = $Arg;
}
}
// Get the values according to the keys and put them to array.
foreach ($ArrayData as $Key => $Info) {
foreach ($KeyNameList as $KeyName) {
${$KeyName}[$Key] = $Info[$KeyName];
}
}
// Create the eval string and eval it.
$EvalString = 'array_multisort(' . join(",", $SortRule) . ',$ArrayData);';
eval($EvalString);
return $ArrayData;
}
$keys = array('stu_no','name','price');
//输出表格
echo "请输入需要排序的数据:
";
echo "
';';
print_r($stu);
echo '
';'
print_r($temp);
echo '
echo "请输入需要排序的数据:";
echo "