私はここで多くの例を見ていますが、それは私のためには機能しません。複数の配列を並べ替えるのに役立つ
私がDBから検索、ソートイベントのリストを持っている:
16.08.2010 12:00:00
から21.08.2010 20:00:00
16.08.2010 20:00:00
から21.08.2010 23:00:00
18.08.2010 17:00:00
から18.08.2010 19:00:00
あなたが見ることができるように、最初のイベントは、16.08から21.08にあり。
私はforeachの日に1つのエントリを取得するように "これを切り詰める"必要があります。
これは私の関数である:
function fullList($data) {
$ev = $data['events'];
$events = array();
// Loop through each event. If event spans over several days, add each day in to new event list
foreach($ev as $e) :
$endDate = strtotime(date('Y-m-d 23:59:59', strtotime($e->endTime)));
$current = strtotime($e->startTime);
// Copy event so data is not overwritten
$newEv = $e;
while ($current <= $endDate) {
//Set start date of event to new date
$newEv->startTime = date('d.m.Y H:i:s', $current);
// Add events to new event list
array_push($events,$newEv);
//Go to next date
$current = strtotime('+1 day', $current);
}
endforeach;
// Need to sort $events here
}
今$events
は、すべてのイベントが含まれていますが、それが日付でソートいません。私はuasortを試しましたが、uasort($array, 'cmp');
は使用できません。
この配列を日付順にソートするにはどうすればよいですか?
これは、MySQL ORDER BYパラメータを使って行う方が効率的です。 – Nazariy
なぜあなたはuasort(またはもっと適切だろう)を使うことができませんか? – Phil
FYI、 '$ e'を' $ newEnv'に代入してコピーしていないので、別の参照を作成するだけです。オブジェクトをコピーするには、[clone](http://php.net/manual/en/language.oop5.cloning.php) – Phil