php usort keep keys
// Use "uasort" instead of "usort"
function order_asc($a, $b) {
return $b["popularity"] - $a["popularity"];
}
uasort(array, "order_asc");
php usort keep keys
// Use "uasort" instead of "usort"
function order_asc($a, $b) {
return $b["popularity"] - $a["popularity"];
}
uasort(array, "order_asc");
array sort php
<?php
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
echo $val;
}
/*
OUTPUT:
apple
banana
lemon
orange
*/
?>
php sort array by value
$price = array();
foreach ($inventory as $key => $row)
{
$price[$key] = $row['price'];
}
array_multisort($price, SORT_DESC, $inventory);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us