Answers for "array sort php callback"

PHP
1

php usort keep keys

// Use "uasort" instead of "usort"
function order_asc($a, $b) {
  return $b["popularity"] - $a["popularity"];
}
uasort(array, "order_asc");
Posted by: Guest on April-05-2020
0

array sort php

<?php

$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
    echo $val;
}
/*
OUTPUT:
apple
banana
lemon
orange
*/
?>
Posted by: Guest on May-14-2020
1

php sort array by value

$price = array();
foreach ($inventory as $key => $row)
{
    $price[$key] = $row['price'];
}
array_multisort($price, SORT_DESC, $inventory);
Posted by: Guest on June-19-2021

Browse Popular Code Answers by Language