Sort array in PHP by value and maintain index association October 3, 2022 by Tarik Billa This should work using asort(): <?php $array = array( 'john' => 2, 'adam' => 3, 'ben' => 10, 'tim' => 1, ); asort($array, SORT_NUMERIC); print_r($array); ?> output: Array ( [tim] => 1 [john] => 2 [adam] => 3 [ben] => 10 ) Checkout the demo. More Related Contents: Removing array of arrays for certain inner values in PHP Can't echo items from array Undefined Offset Array [closed] How to remove duplicate values from a multi-dimensional array in PHP How to solve PHP error ‘Notice: Array to string conversion in…’ Convert multidimensional array into single array create array tree from array list Replace keys in an array based on another lookup/mapping array Strange behavior of foreach when using reference: foreach ($a as &$v) { … } How to sort date array in php? php return only duplicated entries from an array How get all values in a column using PHP? getting a checkbox array value from POST how to pass an array in GET in PHP? Merge array items into string PHP get both array value and array key PHP curly braces in array notation Accessing JSON array after json_decode/multidimensional array Explode string into array with no empty elements? Iterating over a complex Associative Array in PHP Merging two arrays with the “+” (array union operator) How does it work? Remove item from array if it exists in a ‘disallowed words’ array PHP: Create an array for a range Interleaving multiple arrays into a single array Easy way to apply a function to an array what is a good method to sanitize the whole $_POST array in php? [duplicate] foreach with three variables add Remove zero values from a PHP array Convert PostgreSQL array to PHP array PHP: Most frequent value in array