I am fetching dates from db to display the dates on the dropdown menu. It is displaying based on id.I want to sort the data based on dates.I am now getting dates in the below order:
Saturday, March 25
Saturday, April 15
Wednesday, April 5
Saturday, May 6
Saturday, April 29
Wednesday, May 10
Saturday, May 20
i need the data in below order:
Saturday, March 25
Wednesday, April 5
Saturday, April 15
Saturday, April 29
Saturday, May 6
Wednesday, May 10
Saturday, May 20
the code
$dates = \Drupal::service('custom_forms.custom_forms_service')->getDates();
$datesObj = array("" =>"- Select -");
foreach($dates as $date){
$datesObj[$date->id] = $date->date;
echo "<pre>";print_r($datesObj[$date->id]);
}
exit;