2 回答
TA贡献1876条经验 获得超7个赞
使用 ksort() 按键排序
foreach($results as $rowData) {
if ($rowData->title == 'MORNING') {
$eventperDayArray['0'] = $rowData;
} else if ($rowData->title == 'AFTERNOON') {
$eventperDayArray['1'] = $rowData;
} else if ($rowData->title == 'EVENING') {
$eventperDayArray['2'] = $rowData;
} else if ($rowData->title == 'NIGHT') {
$eventperDayArray['3'] = $rowData;
}
if ($i == 5) {
print_r($eventperDayArray);
die();
break;
}
$i++;
}
ksort($eventperDayArray);
eventperDayArray
TA贡献1770条经验 获得超3个赞
ksort()确实按数组上的键排序。
<?php
$arr = [];
$o = new stdclass();
$o->id = 11591;
$o->title = 'abc';
$arr[3] = $o;
$o = new stdclass();
$o->id = 11592;
$o->title = 'xyz';
$arr[2] = $o;
$o = new stdclass();
$o->id = 11589;
$o->title = 'abg';
$arr[0] = $o;
$o = new stdclass();
$o->id = 11590;
$o->title = 'asw';
$arr[1] = $o;
ksort($arr);
print_r($arr);
演示: https : //3v4l.org/hkLCc
- 2 回答
- 0 关注
- 129 浏览
添加回答
举报