Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have some multidimensional arrays like this (I trimmed sub-array values in this example):

Array (     
  [name] => This is my array name,
  [0] => Array ( [id] => 9, [multiply] => 2, [name] => Item name ),
  [1] => Array ( [id] => 24, [multiply] => 1, [name] => Another name, 
                    [sub-array] => Array(has more data here..)
              )
)

I'd like to sort only the numbered keys by the [multiply] field DESCENDING, the [name] array needs to stay at the beginning.

I've tried using usort(), but I need the [name] key to stay as it is.

Any hint what php-function could help me sort my multidimensional arrays?

share|improve this question
1  
You can use recursive function along with array_map() for that. –  bad_boy Feb 22 at 13:21
    
Thanks a lot, I ended up using the similar function array_walk() instead –  3und80 Feb 22 at 23:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.