Last active
January 14, 2016 07:57
-
-
Save platoosom/4c0adf89f783901a0093 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ให้จินตนาการว่าข้อมูลอะเรย์ด้านล่างนี้เป็นชุดข้อมูลจากฐานข้อมูล | |
$datasets = array( | |
array('ID' => '1', 'name' => 'A', 'created' => '2016-01-05 11:00:00'), | |
array('ID' => '2', 'name' => 'E', 'created' => '2016-01-05 11:00:00'), | |
array('ID' => '3', 'name' => 'F', 'created' => '2016-01-05 11:00:00'), | |
array('ID' => '4', 'name' => 'G', 'created' => '2016-01-05 11:00:00'), | |
array('ID' => '5', 'name' => 'B', 'created' => '2016-01-06 11:00:00'), | |
array('ID' => '6', 'name' => 'C', 'created' => '2016-01-02 11:00:00'), | |
array('ID' => '7', 'name' => 'D', 'created' => '2016-01-03 11:00:00'), | |
); | |
$datas = array(); | |
$loop = 0; | |
// เอาวันมาทำเป็นเลขดัชนี | |
foreach($datasets as $dataset){ | |
$loop++; | |
$datas[strval(strtotime($dataset['created']).'.'.$loop)] = $dataset; | |
} | |
// จัดเรียงข้อมูลจากวันที่น้อยไปหามาก | |
ksort($datas); | |
$datasets = $datas; | |
var_dump($datasets); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment