1$inventory = array(
2
3 array("type"=>"fruit", "price"=>3.50),
4 array("type"=>"milk", "price"=>2.90),
5 array("type"=>"pork", "price"=>5.43),
6
7);
8$price = array_column($inventory, 'price');
9array_multisort($price, SORT_DESC, $inventory);
1 $weight = [
2 'Pete' => 75,
3 'Benjamin' => 89,
4 'Jonathan' => 101
5 ];
6 ksort($weight);
1$weight = [
2 'Pete' => 75,
3 'Benjamin' => 309,
4 'Jonathan' => 101
5];
6asort($weight);
7/*
8weight is now:
9Array
10(
11 [Pete] => 75
12 [Jonathan] => 101
13 [Benjamin] => 309
14)
15To sort descending instead use: arsort
16*/
1$inventory = [
2 ['price' => 10.99, 'product' => 'foo 1'],
3 ['price' => 5.99, 'product' => 'foo 2'],
4 ['price' => 100, 'product' => 'foo 3'],
5
6];
7
8$price = array_column($inventory, 'price');
9
10array_multisort($price, SORT_DESC, $inventory);
1 function cmp($a, $b)
2 {
3 return strcmp($a->display_name, $b->display_name);
4 }
5
6 usort($blogusers, "cmp");
7
8 foreach ($blogusers as $bloguser)
9 {
10 ...