sort array by key value in 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);

3.86
7

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

3.86 (7 Votes)
0
3.4
5

                                        function cmp($a, $b)
    {
        return strcmp($a->display_name, $b->display_name);
    }

    usort($blogusers, "cmp");

    foreach ($blogusers as $bloguser)
    {
        ...

3.4 (5 Votes)
0
3
1
Janeheroine 110 points

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

3 (1 Votes)
0
4
1

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

4 (1 Votes)
0
3.78
24

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

3.78 (9 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
php sort data by key php sort associative array by key name sort() php changes key values sort associative array based on a key in php aceenfing order key sort array in php array sort with key php php order array by index key php sort array content ascending by key php sort array by keyasc sort an array php by key php array sort by specific key value php foreach sort on specific key value example php array sort by specific value php sort array without keys sort array base on key php php sort array by value of key sort asociative array by key php array sort with specific key php sort by specific key php array sort using KEY php sort by array specidic key php sort by array key php php dictionary sort php sort array alphabetically by key value php order array keys sort by values and not by keys php php order array with key by value order array by key value php php order by array key php sort by key and value order an array by a specific key php php sort an array by a specific key sort array according key php order by key in php array php array sort by associative key php array sort by object key in an array sort php keep keys php sort array specific order sort array in order by a key in codignater php sort php array of objects by key php object array sort by key sort from array keys in php sort object by key php associative array sort in php by key php sort array manually key value php sort associative array by key php sort associative array by specific key order associative array by key php sorting by key in php sort array by numeric key php php array sorting by key array sort key value php asort by specific key php php sort array by value and key php sort array by value without changing key php sort array by key value alphabetically Sorting an associative array by a specific key with PHP 7.3 sort an array by a specific key php how to sort array with key value iin php php sort keys in array sort array object by key php array sort by using array key php php sort array without changing key sort associative array php by key and value at the same time sort associative array php by key and value sort key value array php sort inner array by key php php sort inner arrays by key make key values order in php php array keys sort php sort objects by key php order objects by key php ordering key numbers array php ordering array keys sort array with given key in php sort array according to keys php php sort array key ascending javascript sort array in php based on key value php sort array by value and keep key php sort array maintain keys php sort by value keep key php sort maintain keys sort an array based on sincgle key value php sort array by specific value of key php sort array by value of key php php sort array by value maintain key php array sort by key asc sort keys associative array php php order array of objects by key php sort array by value keep keys php sort associative array by key sort array by key value in php php object array sort by key value php array sort key name php sort array in array by key sort by array keu value php sort not sorting keys php which of these sort generates new key in php which of these sort generates new keys in php Which of these sort generates new keys in PHP? php sort array by kevalue name arrange array on key in php sort array php by key value sort array by particular key value in php sort by key value in php sorting on key in php sort by value of the key php array key sort in php php array specific order php sort string key php asort by key array key arrange function in php assign key order in array php sort array specific key php how to sort associative array according to key without using any php built in function sort array key php order array php by key value php sort array by value without changing keys sort matrixon key php sort array on key php sort an array according to the key in php order array by keys php php array chage order by key php array sort by value of key sort an array by key in php php object array order by specific value sort array keys from to php sort array keys in php php array sort preserve keys php sorting by key php sort array by string key php sort array by one key how to sort array by key in php order by keys php php sort array by 2 keys array key sort descending php php sort array alphabetically by key Sort array by key value PHP array sort keys php php sort array custom key php sort array of objects by specific key sort objects by key php php sort collection by key value php sort associative array by key names array of obajects sort by key php array of obajects sort by key value php how to sort key values in php array function to sort in php with keys as well php sort list of lists based on key value php sort associative array by key value php sort by subkey array sort php by key value php array sort but to keep keys in php sort an array with arrays from a key how to sort a key value array in php php sort array buy key value how to sort array in php by key php key value sort on value array key sort php how to sort associative array by key in php 7 how to sort associative array by key in php how to sort array with key in php sort alphabetically php function php array sortir tout les id php sort by order order array key value php sort array by key name php php array set key in a specific order php sort array by value of specific key sort array by particular key in php php sort key value on value key value order php sort by key php array php sort by key with condition php sort key value array desc array php add element sort by key php sort array by key value ascending array_ sort key php php sort array key value php sort by key int sort array php by keys php sort array by key value descending php sort keep keys sort array according to key in php sort keys by values php sort keys php sort array by keys in php php sort array by a key php sort with keys php sort array based on key array order by key php left some keyss array order by ke php sort object by key value php php sort array of objects by key php sort associative array by value keep key php array sort values preserve keys php array sort keep keys sort php array by specific key php sort key php array order by key asc sort array key desc php sort array by specific key value alphabetically php sort array by specific key value php array orderby key php php array sort by keys php associative array sort by key value php sorting arrays by key asc sorth php array ans change keys php array key sorter php order array by specific key value php sort by a specefic key array sort by key desc php php sort array by ke sorting array by changing key order in php sorting array by changing key position in php sort key array php php sort by key value php array sort by key name sort array by key in php order array by key php by key php array sort by key desc sort arrays keys php php sort key value array php sorting associative array by key array_sort by key php php sort array descending by key array sort by key value php php sort by specific key php sort value sort data in array by name k sort php php array sort single key php order single array key php order one key of array order array by key implement sortign in PHP php array sort by index php array sort indexed by key php foreach key => $value order arrays on a specific key php php array key exists dynanic key value sort by value php order keys php order keys by value php php sort buy price in object array php sort array by key~value php array sort by value asc array sort by value php order array of array php array order by key value descending php sort only values but not keys in php sort array values with keys php php order array by key value php array multi sort by key array sort in php php sort array by field php sort array with array of keys sort keys based on keys in php sort based on keys in php sorting types in php for numeric values array short by value php php Source Code/Sorting array in ascending and descending order sort array by value php php function to get array value descending sort an array of key values php sort by associative array value array sort by key or value php array sort alphabetically by key sortby php makes array objects sortby php makes object value php ksort sub array how to sort array in php based on name how to short array in hp php sort array by custom key php sort array of objects by key value sort array by value php desc array sort in php bse on key value sort array index key php sort array key pph array of object sort php by key object sort php by key php array sort by value reorder key array php arrange array of arraies by value php php array pair key value sorting php sort array by specific key sort array in array array data asc order php sort associative array sort array according to value in php php associative array sort by value php order array alfabetically on key sort array by number of arrays php sort array based on a value php php sort array by key numeric usort arrya by key php usort arrya by key arrange key manually php arrange array key manual in php sort array by value in php php sort ary by key order array with keys sort an array by key php sorting an associative array using one of the fields in php array order by id php order by key usort php order by key php php sort array per one of the keys php array change order by key php arrange array by specific key php arrange array by key laravel sort array of dictionaries laravel sort array of dictionary order array php by value and change key sort array by key and value php array sort by value of key php specific order assoc array php order id find key value from array php sort php array by specific value array key sort php method array sort in php by key php array of arrays sort by key php sort desc mantain key php reorder array by key jquery order array by key sort by key in php sort an array of arrays based on value in array php php asort number sort array in ascending order in php how to sort associative array by value in php php sort array keys ascending sort in php associative array sort in php php array dot notation sort by key associative array in php sort based on value using insertion sort associative array in php sort based on value sort associative array php by value by using insertion sort get specific key value from array php ksort merge sort array value and key in php how to sort an associative array in php based on key function list sort php how to use sort in particular array in php sort php php sort by value inside a value sort dictionary by lowest to highest number key php sorting with key in php sort associative array based on value php php array sort key array ksort array sort key php arrray order php php array sort key hash sort array by array field order by array value php full array order by big key object sort by key php php order a array based in a key value array sort by specific key php array order by key php php sort array by key asc sort associative array php php sort array keys by another array keys array sorting by key in php php creating function sort array php sort an array based on any key value php sort array of associative arrays key sort array php php array sort by given array key php array order how to sort an array based on key value sort key in array php php sort by keys key sort php php array order by key php sortAssociativeArrayByKey reorder array by key php order associate array in php by value sort arry by key value php php asort put the first last array sort by key php short an array in key des in php php array with key and value sort how to sort array of arrays php php reorder array by specific key order index array php order array php by key sort array by value in associative php php array sort by id sort an array with repect to key in php php ksort integer order associative array by value laravel array sort by key sort array key value php array sort y value descending sorting function in php with keys ascending sorting function in php with keys rksort php array map sort php php array sort by ket asc php sorting associative array by value sort php associative array by value php sort array by a value php sort array of arrays sorting based on key array in php sorting based on key array inphp php sort key array by value next array element with sort php asort php based on key php sort based on value php sort array by key order php sort multidimensional array by specific key order php sort multidimensional array by specific key php sort by key array sort an array based on a key in php in php sort array by key sort array of arrays by time php sort array of arrays by value php foreach key value sort rearrange array key in php sort a particular key in php sort an array by a key sort by key array sort specific key order array by index php php sort array by key descending sort array on the basis of key in php php ksort in first place put numbers sort array on key value php php arraysort key php function sort array by key value php order array element by key find 5 sorted values of array php arroy order by key php SORT BY array map php sort associative array by value php sort array by key php sort keys from array sort array keys from array php phpsort array by key sort array of arrays by value php how to sort array by key name in php php are key value array sorted sort array of associative arrays php how to sort an array by following specific key php array sort by key value sort an array with reference to specific key sort an array key sort by key asc array php order by array key value sort by key value php ksort a specific value in an array ksort in php array array sort by keys php how to sort base on last index php array php array order by key value order by array key php php sort array by key name sort the array by key sort array by value of key key sort sort array value descending php php sort an array by keys php array sort on value php sort array keys alphabetically php sort multidimensional array by specific key value array sort with key name in php array sort with key in php sort php array with keys array sort using key in php sort associative array by keys php sort associative array keys php php array sort keys sort bynkey array php sort an array based on key php php sort array by key ascending php sort array keys php sort array of arrays by key value php sort associative array by specific key value sort by keys php sort by key php sort key value pair array in php php order by key value sort array by key alphabetically php array keys sorting php order associative array by value sort array php by key sort array based on key php php sort array by specific key value sort index array of key php sort array key in php array sort php by key php order an array based on key ordenar array php for keys php sort array by index asc array sort on keys php sort array of array by key php sort array by key value php keysort kosrt php sorting keys in array sort array on certain key sort array based on key order array on specific key rearange array on a specifig ket sort on index key php sort array on key index php sort or traverse array on key php foreach sort on key value php sort array based on specific key php array sort based on array key array order by key how to sort an array in php by specific key ksort php order assosiative array by a specific key php order array by a specific key php php sort associative array by key sort array keys php php sort by array key order list by keys of array php array sory key php sort array by keys array sort by index php sorting using a key in php organise array keys php order array keys php php array key sort sort an associative array keys alphabetical order phph array order sort by key sort php array by key sort by key array php php ksort() array_key sort in php order array by key php php sort array by key order key array php by specific order order key array php php order by key ksort array decrease php php ksort php sort array on key order array key value sort associative array by key php sort array by key php sorting arrays by index php ksort in php sort key php php sort on key sort array keys php arrange aray by key php sort dictionary by value php sort dictionary by key php multidimensional array sort by value php key sort sort array ovject by value js php sort keys sort keyvalue array php how to sort key value pair array in php order an array php by key php sort list by key php sort list by key value php array ksort reorder array php by key how to sort array based on key php how to sort array based on key php sort keys alphabetically sort array by key sort array keys asc sort associative array php by key array sort by key php sort array php sort in ascending order by key php sort array by value sort associative array by key php sort by key php how to sort array by id php array sort by key associative order array of number php php sort reorder keys sort arrayby key value php order array by key php array sort by key php sort array by key
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source