Pre-recorded question

Question #72
How to sort PHP arrays?
Answer

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

3 events in history
Answer by Alphonsio 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 Alphonsio 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 Alphonsio 06/11/2020 at 12:05:14 PM
How to sort PHP arrays?
# ID Query URL Count

Icons proudly provided by Friconix.