hello friends I have an array that looks like this:
array:3 [▼
0 => array:6 [▼
\"date\" => \"2016-05-31 15:08:33\"
0 => \"31 May 16\"
You can use this solution to get the result:
collect($yourArray)->sortBy('Key')->values();
You can convert to a collection
, call the sortBy()
and the convert back to an array
all on one line.
$sortedArr = collect($array)->sortBy('date')->all();
you have to create your own function
array_sort_by_column($array, 'date');
function array_sort_by_column(&$array, $column, $direction = SORT_ASC) {
$reference_array = array();
foreach($array as $key => $row) {
$reference_array[$key] = $row[$column];
}
array_multisort($reference_array, $direction, $array);
}
You can use usort()
with custom comarison function.
function sortByDate($arr1, $arr2)
{
$tmp1 = strtotime($arr1['date']);
$tmp2 = strtotime($arr2['date']);
return $tmp1 - $tmp2;
}
usort($array, 'date');