0

I have this php array:

Array ( [5] => Theme [8] => More [6] => Plugins [7] => Settings [1] => Blog [2] => Images [3] => Pages [4] => Social Media )

I need to sort it by the number of the array, so this array should be:

Array ( [1] => Blog [2] => Images [3] => Pages [4] => Social Media [5] => Theme [6] => Plugins [7] => Settings [8] => More )

How can I go about sorting this array into the outcome I need in php?

Thank you.

EDIT: I need to sort the array by the name of the multidimensional array, not the value.

potashin
  • 44,205
  • 11
  • 83
  • 107
Austin Collins
  • 439
  • 3
  • 13

1 Answers1

1

Take a look at ksort() function:

ksort($a);
var_dump($a);  

Output:

array(8) {
  [1]=>
  string(4) "Blog"
  [2]=>
  string(6) "Images"
  [3]=>
  string(5) "Pages"
  [4]=>
  string(12) "Social Media"
  [5]=>
  string(5) "Theme"
  [6]=>
  string(7) "Plugins"
  [7]=>
  string(8) "Settings"
  [8]=>
  string(4) "More"
}

Demonstration

potashin
  • 44,205
  • 11
  • 83
  • 107