【发布时间】:2015-12-01 11:29:57
【问题描述】:
您好,我创建了一个 4 行 5 列的数组。我现在想按数组中的随机数对数组进行排序,而不是如何对多维数组进行排序。我在网上看到我可能对每个循环都使用了一个,但如果我要使用一个,我不确定在哪里放置它。另外,我不确定如何告诉 sortarray 我要对哪一列进行排序,因为我没有任何输出 id。任何帮助将不胜感激。
<?php
$vyear = 1;
$vmonth= 3;
$date = "2015-11-25";
$t = 0;
echo date("M-y") . "<br>";
$startdate = "2009/06/01";
$start = strtotime($date);
$currentdate = $start;
$newdate = strtotime ( $t .'month' , strtotime ( $date ) ) ;
$ndate = date ( 'm-Y-d' , $newdate );
echo $ndate;
echo "<br>";
echo "<br>";
echo $date;
$times_table = array();
for($i = 0; $i <= 3; $i++){
$times_table[$i] = array();
}
echo "<pre>";
for($i = 0; $i <= 3; $i++){
for($j = 0; $j <= 4; $j++){
if ($j == 0){
$times_table[$i][$j]= "Version 4" ;
}
else if ($j == 1){
$cur_date = date("M-y", $currentdate);
$currentdate = strtotime('+1 month', $currentdate);
$times_table[$i][$j]= $cur_date ;
echo $cur_date . ">". "<br />";
}
else{
$times_table[$i][$j]= "gary" ;
}
if ($j == 3) {
$numbers = mt_rand(1, 100);
$times_table[$i][$j]= $numbers ;
}
if ($j == 4){
if($i == 0 || $i == 3)
{
$pay = "P";
$times_table[$i][$j]= $pay ;
}
else{
$int = "I";
$times_table[$i][$j]= $int ;
}
}
}
}
// echo $times_table[1][3] ;
print_r($times_table);
echo "</pre>";
?>
【问题讨论】:
标签: php arrays sorting multidimensional-array