peterjc Posted June 7, 2008 Share Posted June 7, 2008 There are php sort() function to sort array. But the problem that i face is how to sort the two-dimensional array and sort the date in desending order? the array is as below $data = array(); $data[0][0] = "2008-05-23"; $data[0][1] = "data 1"; $data[1][0] = "2008-05-15"; $data[1][1] = "data 2"; $data[2][0] = "2008-06-06"; $data[2][1] = "data 3"; $data[3][0] = "2008-05-08"; $data[3][1] = "data 4"; Any help is appreciated. Thank in advance. Link to comment https://forums.phpfreaks.com/topic/109148-sorting-date-in-php-array/ Share on other sites More sharing options...
DarkWater Posted June 7, 2008 Share Posted June 7, 2008 What are you actually asking? You want the whole array to be sorted based on the date? Ie: $data[0][0] = "2008-05-23"; $data[0][1] = "data 1"; $data[1][0] = "2008-05-15"; $data[1][1] = "data 2"; $data[2][0] = "2008-06-06"; $data[2][1] = "data 3"; $data[3][0] = "2008-05-08"; $data[3][1] = "data 4"; Becomes: $data[0][0] = "2008-05-08"; $data[0][1] = "data 4"; $data[1][0] = "2008-05-15"; $data[1][1] = "data 2"; $data[2][0] = "2008-05-23"; $data[2][1] = "data 1"; $data[3][0] = "2008-06-06"; $data[3][1] = "data 3"; Link to comment https://forums.phpfreaks.com/topic/109148-sorting-date-in-php-array/#findComment-559876 Share on other sites More sharing options...
PFMaBiSmAd Posted June 7, 2008 Share Posted June 7, 2008 array_multisort($data, SORT_DESC); echo "<pre>"; print_r($data); echo "</pre>"; This basically sorts by the first dimension in the array. This operates similar to a ORDER BY clause in a sql query. Check the array_multisort section in the manual for more. Link to comment https://forums.phpfreaks.com/topic/109148-sorting-date-in-php-array/#findComment-559878 Share on other sites More sharing options...
peterjc Posted June 8, 2008 Author Share Posted June 8, 2008 Thank a lot guy. It work... Link to comment https://forums.phpfreaks.com/topic/109148-sorting-date-in-php-array/#findComment-560221 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.