Skip to content

Instantly share code, notes, and snippets.

@platoosom
Created January 14, 2016 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save platoosom/a2ad91cfe9fc364d1d32 to your computer and use it in GitHub Desktop.
Save platoosom/a2ad91cfe9fc364d1d32 to your computer and use it in GitHub Desktop.
<?php
// ให้จินตนาการว่าข้อมูลอะเรย์ด้านล่างนี้เป็นชุดข้อมูลจากฐานข้อมูล
$datasets = array(
array('ID' => '1', 'name' => 'A', 'created' => '2016-01-05 11:00:00'),
array('ID' => '2', 'name' => 'B', 'created' => '2016-01-06 11:00:00'),
array('ID' => '3', 'name' => 'C', 'created' => '2016-01-02 11:00:00'),
array('ID' => '4', 'name' => 'D', 'created' => '2016-01-03 11:00:00'),
);
$datas = array();
// เอาวันมาทำเป็นเลขดัชนี
foreach($datasets as $dataset){
$datas[strtotime($dataset['created'])] = $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