sort multidimensional array in php

Solutions on MaxInterview for sort multidimensional array in php by the best coders in the world

showing results for - "sort multidimensional array in php"
David
10 Feb 2018
1function sortByAge($a, $b) {
2    return $a['age'] > $b['age'];
3}
4$people=[
5    ["age"=>54,"first_name"=>"Bob","last_name"=>"Dillion"],
6    ["age"=>22,"first_name"=>"Sarah","last_name"=>"Harvard"],
7    ["age"=>31,"first_name"=>"Chuck","last_name"=>"Bartowski"]
8];
9
10usort($people, 'sortByAge'); //$people is now sorted by age (ascending)
Kori
05 Jun 2019
1array_multisort(array_map(function($element) {
2      return $element['order'];
3  }, $array), SORT_ASC, $array);
4
5print_r($array);
Kamil
24 Jun 2018
1		$keys = array_column($array, 'Price');
2
3		array_multisort($keys, SORT_ASC, $array);
4	
5		print_r($array);
Karim
15 Jul 2017
1<?php
2function sortByPrice($a, $b){
3	return $a['price'] > $b['price'];
4}
5
6$items = [
7    ['label' => 'cake', 'name' => 'Cake', 'price' => 150],
8    ['label' => 'pizza', 'name' => 'Pizza', 'price' => 250],
9    ['label' => 'puff', 'name' => 'Veg Puff', 'price' => 20],
10    ['label' => 'samosa', 'name' => 'Samosa', 'price' => 14]
11];
12
13//Sort by Price
14usort($items, 'sortByPrice');
15//print_r($items);
16
17print "<br/> After Sort by Price printing: <br/>";
18foreach($items as $item){
19	print $item['name']." ".$item['price']."<br/>";
20}
21$newArray = array_column($items, 'price', 'name');
22
23// find max, min, and toal sum of array
24$totalExp = array_sum(array_column($items, 'price', 'name'));
25$maxPrice  = max(array_column($items, 'price', 'name'));
26$minPrice  = min(array_column($items, 'price', 'name'));
27
28print "Total Expenses : ".$totalExp."<br/>";
29print "What is Costly Item : ".$maxPrice.' ('.array_search($maxPrice, $newArray).")<br/>";
30print "What is Cheap Item : ".$minPrice.' ('.array_search($minPrice, $newArray).")<br/>";
31
32?>
queries leading to this page
php array sort multidimensional by valuefunction to sort two dimensional array in php by two valuesmultidimentionnal array sort phpphp sort multidimensional array one linehow to re arrange multi dimensional arrayphp sort two dimensional array by max valuesort multiple arrays against eachother phpmultidimensional array sort phpmulti sort phpsort dimensional array and divide in multiple array as subsequesnt in phprearrange multi dimentional array based on valueorder multiple arraysort array by value multidimensional phpsort array php deminsing valuephp sort a multidimensional arrayphp array sort custom orderphp sort multidimensional array by number of keysmultidimensional array sort example php 8sort array multidimensional php valuephp possible sub arrayphp multidimensional array sort element php 2 dimension array sort by key valuephp order a bidimensional array usortphp array multisort 28 29multisort in phpphp sort multidimensional array by key descendingsort multidimensional array php laravelphp sort order multidimensional arrayphp sort multidimensional array multiple columnsphp usort multidimensional arrayphp subarraysort multidimensional object array by string value php ascmulti level array sorting in phphow to sort multidimensional array in phpmultidimensional array php sortsorting multisort array in phparray multisort phpphp sort multi arrayusort multidimensional array phpphp multidimensional array sort by columnsort a2d array phparray muktisortphp sort 2d array by valuesort a multidimensional array in phporder multidimensional array in php by valuesort multidimensional array php no indexarray multisort samplephp sort 2d arrayphp sort array by multiple fieldsarray sort multidimensional phpphp sort multiple array with value ismultidimensional array sort by desc in phpsort multidimensionnal array phparray sort key multidimensionalphp sort multidimensional array indexphp sort array by value of subarrayphp sort multidimensional array by specific keyarray multisortphp sort nested array by keymultidimensional array sortingphp sort multidimensional array content ascending by keyphp order multidimensional array by valuemultiple array sorting by value in phpphp sort multidimensional array get specific columnphp multiple sortphp how to create multidimensional arrayarray multisort lettersimple array sorting function in phpphp sort vs array multisortphp sort array by sub array keysort array php by value multidimensionalsort multidimensional object array by string value phpphp sort multidimensional associative array by value alphabeticallysort php multidimensional array by keysort array by time multidimensional phpsort by key in multidimensional array phpphp sort associative array third level multisortphp multidimensional array sort by column descdynamic array multidimensional sorting phpphp sort multidimensional array by first valuephp sort multi dimensional array by valuehow to sort an multidimensional array by key value in phpsort array by numeric multidimensional phpphp sort array by value multidimensional arrayarray multisort couldnot be converted to floatphp multidimensional array sortsort arry with tow values phpphp sort array by key multidimensional3rd dimensional array sort with multidimensional array phpphp merge two multidimensional array and sort by value alphabeticallyphp arraymultisort usort php multidimensional arrayphp multidimensional array sort by indexsort multidimensional arrayphp array sort based on nested array valuephp sort array multiple columnssort uone array in multiple array valuearraymultiple order phpsort php multidimensional array based on filter selectionphp sort array by value in subarrayphp sorting multidimensional array by keysort 2d simple string array by specific order array phpphp sort field in multidimensional arrayphp array sort by value multidimensionalsearch multidimensional array key phparray multisort in phporder array multidimensional phpsort multidimensional array by another array values in php site 3astackoverflow comphp array column sort array multisortmulti dimensional array order by value php4th dimensional array sort with multidimensional array phpphp sort by value in multidimensional arrayphp sort by multiple valuesphp sort multidimensional array by custom valuesub arrays in phpphp array sort sub fieldsort array multiple conditions phpphp sort arrays with subarray valuessorting n dimensional array based on one valuearray multisort 28array map 29 in phpphp multidimensional array order element to firstphp sort multidementional by value or arrayphp sort array by columnhow to get array 27 sub in phparray flip multidimensional phpmultidimensional array sort by desc value in phpphp array diff sorti le manquantphp order by value 2d arraysort by multidimensional value phpphp how to sort multidimensional arraythree dimensional array sorting phpsort multidimensional array in descending order phpsort array php by value 2dorder nested arrayphp sort multidimensional array by array keyarray multisort phptwo keys multisort phpmultidimensional array sort in phpphp sort multidimensional sortchange order of multidimensional array phpphp sort nested array by valueorder array by value php 2dsort multidimensional array by keys phparray multisort with 2 sorting keys phpsort multidimensional array php by keysort two dimensional array phpphp sub listin array php multidimensionalsubstr 28 29 with array phpphp sort multidimensional array with a key usortphp multidimensional array order by valuesort multidimensional array php with keyphp sort json arrayphp sort subarray from 2d arrayphp sort multidimensional associative array by valuearray multisort string matchtwo dimensional array sort in phpmultisort php array columnalfabetic sort multidimensional array phpsort asc in phpsubtract array from array phpphp sort array by multiple valuesphp array multi sort does not worksort multidimensional array by key phpfunction to sort two dimensional array in php sort multidimensional array php no keyhow to sort multidimensional associative array in phpphp reorder multidimensional array by valuesort multidimensional array by key valuephp sort multidimensional array by sting valuearray column with array sort phpsorting multidimensional array in phpphp sort array by multiple columnsphp sort multidimensional array by value high to lowsort multidimensional array order by another array values in phpphp sort arrayphp custom sort multidimensional arrayphp sort multidimensional array by 2php sort multidimensional array by column valuesort nested array in phparray sort multisorting multidimensianal arrays phpphp muti array how to sortorder multidimensional array php ascphp sort multidimensional array custom2d array sort in phpphp array multisort array1 sort order as variable1 dimensional array sorting in php examplephp order array by value in sub arrayphp sort bidimensional arraywrite down function to sort a two dimensional array using phpsort multidimensional array by number of elements phpsort a compund arraysort multidimensional array by value phpsort multidimensional array in php with valuesphp sort multidimensional array by arrayphp sort multi array by valueselect sub array phpphp array multi sort by keysort php multidimensional arraysort by column array phpphp sort desc multidimensional array by valuephp array column array multisortorder multidimensional array php by value and ascarray multisort by key overwrite phpsort multidimensional associative array phpfunction arraymultisortsort ascending order wise 3d array basis of column in phpsorting multidimensional array phpphp sort multidimensional array by column ascendingsorting array phpsort multidimensionna larray phpsort multidimensional array by another array values in phpmulti sort decending phpmultidimensional array sort by valuephp sort multidimensional array by value ascendingphp order array multidimensionalsort arrays based on sub arrays inner value phpphp sort array by value multidimensionalorder key array multiple phpphp sort by multiple array keyphp sort array of arraysphp merge and sort multi arraysort associative multidimensional array phpin array multidimensional phpsort multidimesional array based on particular key in phpsorting a multidimensional array in phphow to sort two dimensional array in phpsort a 2d array in phpphp sort 2 arrays based on valuesort php multidimensional array based on filterorder array by value nested phpmultidimensional array sortphp sort multidimensional arraysphp order multidimensional array by key valuephp sort multidimensional arrayphp natural sort multidimensional arrayphp sort array two dimensionalphp simply sort a compund arrayphp sort multidimensional array by lengthphp sort multidimensional array by specific key string valuesort column php 5 6php array sort by columnmultidimensional array sorting in phpsort and array in php by multiple nested valuesarray multisort 28 29 phparray sort by value php multilanguagephp multidimension array sort bysort array by sub item php 5csort multiple dimensional in phpphp array multi sort 1 and 10 not workingphp sort array by nested valuephp array sort by multiple valuesubarray phpphp how to sort a multidimensional array by valuesort nested array php by valuephp properly sort a two dimensional frist by columnphp multi array sortcan i apply sort on multi dimensional arraysort column in array phpphp sort multidimensional array by specific key valuephp sort order by value in multidimensional arrayphp order array by subarray valuephp sort multidimensional array by indexarray mulitsortsort array by value php multiphp sort multidimensional array by 2nd level keyarray sort key multidimensional phpsort multidimensional array phporder multidimensional array phparray multidimensional php order by valuephp sort multidimensional array by true falsephp sort array multidimensional array using value alphabeticallysort multidimensional array by index phpsort dimensional array in phpphp sort multidimensional array by value ascphp sort subarrays by lengthphp sort associative array by multiple valuesphp multi sortsort 2d array phphow to sort multidimensional array by case insensitive in phpphp array sort multidimensionalafter array multisort the element values are changed why 3farrange in ascending order to multidimensional array by value phporder multidimensional array by value phpphp sort array by subarray valuesorting an array phpphp multisortphp sort multidimensional inner arraysort float values on column multi dimensional array in phpphp array multisort multiple columnssort multidimensional array by the hishest value phpmultisort order by value in phpsort array php multidimensionalphp sort by name in mulsort multidimensional array php by valuearray multi sort phpphp sort 2d array by a value in a named subarrayphp multidimensional array sort by value stringksort multidimensional array phpphp order multi arraysort php multidimensional array based on variable valueorder multidimensional array php by valuesort multi array phpsort associative 2d array in phpmultiarray sort phpphp sort value multidimensional arrayhow to sort multidimentional array phpphp sort two dimensional arrayphp properly sort a two dimensional by columnphp multisort multidimensional arraysort an array using a column of the array phpphp sort multidimensional array of string case insensitivephp sort by key multidimensional arraysort multiarray by value phpphp two dimensional array sort by valuemultidimensional array sorting examplehow to sort 2d array in phpsort multidimensional array by valuephp sort multidimensional array by value of keyphp sort array with multiple by 2php sort multidimensional array by multiple valuesphp properly sort a two dimensional array by columnphp sort array multidimensional by valuearray multisortsort array multidimensional php2d array sort phpphp sub arrayphp sort multidimensional array by 2 valuesacessando array multidimensional phpsort a multidimensional arraysort multiple array phpphp array sort two by valuephp sort multidimensional array by column namephp muiltiy arry sort by array valuesort array of arrays phpphp array multisortmultisort 28 29 phpsort multidimensional array by column phpsort multidimensional array according to another array in phparray sort php multidimensionalsort multidimensional array php 5chow to sort an array of double digits in phpphp array sort by key multidimensionalphp sort multidimensional array by value alphabeticallysort a multi level associative array phpphp sort array 2 dimensional arrarayphp sort multidimensional array by key value descendingsort multidimensional array by item phpmultidimensional array array sort by valuesort a multidimensional array in php based on particular key valuesort mutitple mutitdimensional array in phpsort php array multidimensionalphp sort multi dimensional arrayreorder array columns in phpphp array multi sort by valuehow to sort multidimensional array in php according to valueorder multidimensional array by some value phpsort array 2d phparray multisort modulehow to sort a multidimensional array in phpsort multi array by value phporder 2d array on valluehow to sort value of multidimensional array in phpphp sort array multidimensoinal array php sorting multidimensional arraysort a 2d array phpphp multidimensional array sort by specific valuephp sort multidimensional array by keysort multidimensional array php assending orderphp sort multidimensional array value by datearray column array multisortmultidimensional array sort by value in phpsort multidimensional array of strings and many numbers phphow to sort 2 d array phptwo dimensional array sort phpphp arry multisortphp asort multidimensional arraysort multidimensional nested array phpphp sort multi array by keysort array on the basis of key value multidimensional phpsort multidimensional array by key value phpsort multidimesional array in php based on given keysub array from array phpsort array by subarray value phpphp sort multidimensional array by value non case insensitivephp order multidimensional array by highest valuesort multi dimension array phpphp array sort by 2 valuesphp sort column of multidimensional arrayarray multisort 2 arrays against a mainmultisort php sort asc 7csort natural 7csort flag casesub array from a array phphow to sort an multidimensional array in phpsort multidimensional array by particular valuephp sort multidimentional array with value of decimal pointsubstsr phpphp sort multidimensional array by valuephp sort multidimensional array by priority fielsort value by key php multidimensional arraysort multidimensional array by another array string value in phpphp order 2d array bysort multidimensional array php by key valuemultisort array in phpphp sort multidimensional array by key valuephp array multisort multidimensionalphp sort multidimensional array by another arrayphp sort multidimensional array by 2 valuesphp multi array sort by keyphp sort array sub valuephp sort multidimensional object by valuephp multidimensional array sort by key valuephp sorting multidimensional array by valuephp sort array multidimensionalphp sort multidimensional array by value uknown keyphp sort multidimensional array by value descendingphp sort multidimensional array using another arrayphp sort multidimensional array by columnphp array sorting multidimentiaonalarray multisort key valuephp sort multidimensional array two columnsorder 3 multidimensional array phpphp sort multidimensional array by array columnphp multi sort string and numberphp sorting multi dimensional arraysorting multidimensional arraysort 2d array php by value of keyhow to sort a 2d array based on on ecolumn phpphp sort multiple array with valuerearrange array columns in phpphp sort array with multiple valuessort multidimensional array in phparray msort in laravel arrayphp sort multidimensional array by multiple columnsphp sort two dimensional array by columnsort multidimensional array php by two valuesphp array multisortphp sort multi level arraysort multidimensional array php for amountsort multidimensional array in php