0

In my user_table, I have "UID", and "Gameid". And of course, when I run the query I get something like:

array() {
 [0] => array() {
  UID    => 1,
  gameid => 334613
 },
 [1] => array() {
  UID    => 2,
  gameid => 704234
 },
 [2] => array() {
  UID => 3,
  gameid => 704234
 }
}

The UID is auto incremented, and the gameid is based off what the user is playing currently based off steam and the value is always going to be random. So I want to take the above arrays and place them into a new array sorted by gameid.

I hope that makes sense, let me know if I need to clarify, thank you in advanced.

Sorry for not explaining right,

I'm trying to get the above array into this:

$array = array (
    (334613) => array (
        [0] => 1
    ),
    (704234) => array (
        [0] => 2,
        [1] => 3
    )
);

Thank you again!

Ialon131
  • 13
  • 3
  • http://php.net/manual/en/array.sorting.php – Daniel Faure May 21 '18 at 23:13
  • Possible duplicate of [How to sort an array of associative arrays by value of a given key in PHP?](https://stackoverflow.com/questions/1597736/how-to-sort-an-array-of-associative-arrays-by-value-of-a-given-key-in-php) – Will B. May 21 '18 at 23:15
  • 4
    When youu "run the query" then there's also the option to have the database sort results right away. – mario May 21 '18 at 23:18
  • 1
    In short https://3v4l.org/RZq10 `array_multisort(array_column($array, 'gameid'), SORT_DESC, $array);` Use `$newArray = clone $array;` if you don't want to pass-by-reference – Will B. May 21 '18 at 23:21

0 Answers0