以下内容应按上升时间排序驱动程序数组:
cell.someButton.layer.cornerRadius = floor(cell.someButton.frame.height/2)
此实际输出类似于:
function sortDrivers($a, $b)
{
if (floatval($a->fastestLap) === floatval($b->fastestLap)) {
return 0;
}
return floatval($a->fastestLap) < floatval($b->fastestLap) ? -1 : 1;
}
Log::info("Before:");
foreach($drivers as &$driver){
Log::info($driver->driverCode . " - " . floatval($driver->fastestLap));
}
usort($drivers, "sortDrivers");
$position = 0;
foreach($drivers as &$driver){
$driver->position = ++$position;
$driver->save();
}
Log::info("After:");
foreach($drivers as &$driver){
Log::info($driver->driverCode . " - " . floatval($driver->fastestLap) . " - " . $driver->position);
}
虽然显然有一些趋势是增加单圈时间,但有几位车手出现在错误的位置。
为什么?
答案 0 :(得分:0)
道歉。我使用的是错误的排序功能,而不是上面发布的功能。