Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php sort multidimensional array

$inventory = array(
   array("type"=>"Fruit", "price"=>3.50),
   array("type"=>"milk", "price"=>2.90),
   array("type"=>"Pork", "price"=>5.43),
);

$prices = array_column($inventory, 'price');
$inventory_prices = array_multisort($prices, SORT_DESC, $inventory);

$types = array_map(strtolower, array_column($inventory, 'type'));
$inventory_types = array_multisort($types, SORT_ASC, $inventory);
Comment

php sort multidimensional array

array_multisort(array_map(function($element) {
      return $element['order'];
  }, $array), SORT_ASC, $array);

print_r($array);
Comment

sort multi array php

		$keys = array_column($array, 'Price');

		array_multisort($keys, SORT_ASC, $array);
	
		print_r($array);
Comment

sort multidimensional array php by key

$people= array(
    array("age"=>54,"first_name"=>"bob","last_name"=>"Dillion"),
    array("age"=>22,"first_name"=>"darah","last_name"=>"Harvard"),
    array("age"=>31,"first_name"=>"ahuck","last_name"=>"Bartowski"),
);

echo '<PRE>';
print_r($people);


$keys = array_column($people, 'first_name');
print_r($keys);

array_multisort($keys, SORT_ASC, $people);

print_r($people);
Comment

php sort multidimensional array by value

usort($myArray, function($a, $b) {
    return $a['order'] <=> $b['order'];
});
Comment

php sort multidimensional array by value

function sortByOrder($a, $b) {
    return $a['order'] - $b['order'];
}

usort($myArray, 'sortByOrder');
Comment

php sort multidimensional array by key

function buildSorter($key) {
    return function ($a, $b) use ($key) {
        return strnatcmp($a[$key], $b[$key]);
    };
}

usort($array, buildSorter('key_b'));
Comment

PREVIOUS NEXT
Code Example
Php :: laravel join 
Php :: round numnero php 
Php :: php create zip from folder 
Php :: php array size 
Php :: password required wp 
Php :: PHP executable not found. Install PHP and add it to your PATH or set the php.executablePath setting in linux 
Php :: request get query string laravel 
Php :: laravel model create array 
Php :: How to display image from aws s3 in laravel blade 
Php :: laravel seed fresh 
Php :: laravel order by relationship 
Php :: convert float to integer laravel 
Php :: javascript php loop 
Php :: php round() function 
Php :: php get current time and date 
Php :: magento 2 print php error 
Php :: remove last character from string in php 
Php :: carbon months between dates 
Php :: install soap in php linux 
Php :: get full current url in laravel 
Php :: laravel blade form old value 
Php :: if condition inside echo in php 
Php :: laravel timestamp 
Php :: Delete an array in multidimensional array php 
Php :: php set timezone 
Php :: check current pages is a child page wordpress 
Php :: php json request get value of an array element 
Php :: iteration in php 
Php :: php empty array 
Php :: exec command not working in php but works in terminal 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =