php Seřadit pole podle klíče
$weight = [
'Pete' => 75,
'Benjamin' => 89,
'Jonathan' => 101
];
ksort($weight);
php pole Seřadit podle hodnoty klíče
To PHP sort array by key, you should use:
ksort() (for ascending order) or krsort() (for descending order).
To PHP sort array by value, you will need functions:
asort() and arsort() (for ascending and descending orders).
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)
php pořadí pole podle konkrétního klíče
function cmp($a, $b)
{
return strcmp($a->display_name, $b->display_name);
}
usort($blogusers, "cmp");
foreach ($blogusers as $bloguser)
{
...