Question #63   Submitted by Answiki on 06/11/2020 at 12:05:14 PM UTC

How to sort PHP arrays?

Answer   Submitted by Answiki on 09/19/2021 at 09:17:55 AM UTC

There are many ways to sort PHP arrays:


Sort by values:

  • asort(): in ascending order
  • arsort(): in descending order

Sort by keys:

  • ksort(): in ascending order
  • krsort(): in descending order

Sort by user-defined function:

  • uasort(): sort by values
  • uksort(): sort by keys
  • usort(): sort by values (do not maintain key association)

Multidimensional arrays:

  • array_multisort()


Full reference here : https://www.php.net/manual/en/array.sorting.php

4 events in history
Answer by Answiki on 09/19/2021 at 09:17:55 AM

There are many ways to sort PHP arrays:


Sort by values:

  • asort(): in ascending order
  • arsort(): in descending order

Sort by keys:

  • ksort(): in ascending order
  • krsort(): in descending order

Sort by user-defined function:

  • uasort(): sort by values
  • uksort(): sort by keys
  • usort(): sort by values (do not maintain key association)

Multidimensional arrays:

  • array_multisort()


Full reference here : https://www.php.net/manual/en/array.sorting.php

Answer by Answiki on 06/11/2020 at 01:23:06 PM

There is different ways to sort PHP arrays:


Sort by values:

  • asort(): in ascending order
  • arsort(): in descending order

Sort by keys:

  • ksort(): in ascending order
  • krsort(): in descending order

Sort by user-defined function:

  • uasort(): sort by values
  • uksort(): sort by keys
  • usort(): sort by values (do not maintain key association)

Multidimensional arrays:

  • array_multisort()


Full reference here : https://www.php.net/manual/en/array.sorting.php

Answer by Answiki on 06/11/2020 at 12:18:50 PM

There is different ways to sort PHP arrays:


Sort by values:

  • asort(): in ascending order
  • arsort(): in descending order

Sort by keys:

  • ksort(): in ascending order
  • krsort(): in descending order

Sort by user-defined function:

  • uasort(): sort by values
  • uksort(): sort by keys
  • usort(): sort by values (do not maintain key association)

Multidimensional arrays:

  • array_multisort()

Question by Answiki 06/11/2020 at 12:05:14 PM
How to sort PHP arrays?
# ID Query URL Count

Icons proudly provided by Friconix.