“Array de classificação PHP por chave” Respostas de código

Classificar a matriz por valor -chave no 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);
Fierce Flamingo

Array de classificação PHP por chave

  $weight = [
    'Pete' => 75, 
    'Benjamin' => 89,
    'Jonathan' => 101
  ];  	
  ksort($weight);
Xenophobic Xenomorph

Array de classificação PHP por chave específica


usort($array, function ($a, $b) {
  return ($a['specific_key'] < $b['specific_key']) ? -1 : 1;
});
Matteoweb

Matriz de matriz de classificação PHP por chave

$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);
Matteoweb

Classificação da matriz PHP pelo valor -chave

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).
Envious Eagle

Array PHP Classificação por chave

ksort(array &$array, int $sort_flags = ?): int
Fabi Curti

Respostas semelhantes a “Array de classificação PHP por chave”

Perguntas semelhantes a “Array de classificação PHP por chave”

Mais respostas relacionadas para “Array de classificação PHP por chave” em PHP

Procure respostas de código populares por idioma

Procurar outros idiomas de código