php multidimensional array sort by value code example
Example 1: php sort array by key
$weight = [
'Pete' => 75,
'Benjamin' => 89,
'Jonathan' => 101
];
ksort($weight);
Example 2: sort array of objects javascript by value
let orders = [
{
order: 'order 1', date: '2020/04/01_11:09:05'
},
{
order: 'order 2', date: '2020/04/01_10:29:35'
},
{
order: 'order 3', date: '2020/04/01_10:28:44'
}
];
console.log(orders);
orders.sort(function(a, b){
let dateA = a.date.toLowerCase();
let dateB = b.date.toLowerCase();
if (dateA < dateB)
{
return -1;
}
else if (dateA > dateB)
{
return 1;
}
return 0;
});
console.log(orders);