Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

How can i sort something like this

$a = array(
        0  =>  array(
                 'field' => array( 
                            'id'=>'valueid'
                  )
        )
); 

by valueid? I have managed to sort it by field but i can't realize how to do this weird sorting

share|improve this question
 
Not sure what you mean by "sort". –  Timothy Choi Dec 5 at 12:07
 
you may need uasort –  bansi Dec 5 at 12:10
 
Sorting the $a(0=>array()) by that 'valueid' –  Mihai Dec 5 at 12:11
add comment

2 Answers

usort($a, function($e1, $e2) {
    return $e1['field']['id'] > $e2['field']['id'];
});
share|improve this answer
 
This is the array Array ( [0] => Array ( [field] => Array ( [0] => Array ( [id] => value ) ) ) } –  Mihai Dec 5 at 12:27
 
I'm not getting what do you want to sort then. –  user2928326 Dec 5 at 12:38
 
How can i use usort for my prev commen array? –  Mihai Dec 5 at 12:39
add comment

Use uasort()

uasort($a, function($x, $y) {
    return $x['field']['id'] > $y['field']['id'];
});
share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.