Answers for "sort array of arrays by value php"

PHP
2

php sort array of array by key

$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);
Posted by: Guest on August-25-2020
0

php sort array by value length

function sortByLength($a,$b){
    return strlen($b)-strlen($a);
}
usort($array,'sortByLength');
Posted by: Guest on September-23-2020

Code answers related to "sort array of arrays by value php"

Browse Popular Code Answers by Language