php Seřadit pole podle klíče
$weight = [
'Pete' => 75,
'Benjamin' => 89,
'Jonathan' => 101
];
ksort($weight);
php Seřadit pole podle klíče
$inventory = [
['price' => 10.99, 'product' => 'foo 1'],
['price' => 5.99, 'product' => 'foo 2'],
['price' => 100, 'product' => 'foo 3'],
];
$price = array_column($inventory, 'price');
array_multisort($price, SORT_DESC, $inventory);
Seřadit pole podle hodnoty klíče v php
$inventory = array(
array("type"=>"fruit", "price"=>3.50),
array("type"=>"milk", "price"=>2.90),
array("type"=>"pork", "price"=>5.43),
);
$price = array_column($inventory, 'price');
array_multisort($price, SORT_DESC, $inventory);
php Seřadit pole podle hodnoty a zachovat klíč
$weight = [
'Pete' => 75,
'Benjamin' => 309,
'Jonathan' => 101
];
asort($weight);
/*
weight is now:
Array
(
[Pete] => 75
[Jonathan] => 101
[Benjamin] => 309
)
To sort descending instead use: arsort
*/
php řadit pole odebrat klíče
$arr = array(1, 2, 3);
unset($arr[0]);
$arr = array_values($arr);
print_r($arr);
//Array ( [0] => 2 [1] => 3 )
php rsort Zachovat klíče
//Sort an array in reverse order and maintain index association
arsort($myArray)