Hello. For example, I have input:

<input name="arr[1][2]" value="a"> <input name="arr[1][3]" value="b"> <input name="arr[1][1]" value="c"> 

At the output, I get an array:

 Array ( [1] => Array ( [2] => a [3] => b [1] => c ) ) 

And how do I set the position of these values? Here is if I received the input as described above, and the array should be formed:

 Array ( [1] => Array ( [1] => c [2] => a [3] => b ) ) 

I tried asort, ksort, etc., but it does not work ...

    1 answer 1

    Perhaps you somehow did not use ksort correctly?

     $array = [1 => [2=>'c', 3 => 'a', 1 => 'b']]; ksort($array[1]); print_r($array); 

    Displays:

     Array ( [1] => Array ( [1] => b [2] => c [3] => a ) ) 

    http://sandbox.onlinephpfunctions.com/code/6967188fd2b95e79d18441a43bd1568247362932

    Specifically your case

     $array = $_GET['arr']; ksort($array[1]); print_r($array); 
    • Well yes. I didn’t go there myself - apparently with prosoni ksort called with = ($ arr = ksort ($ arr [1]); - Shevtsov Eugene