sorting - How to sort an array in php based on contained associated array? -


i have array of associative arrays:

a[0] = array("value" => "fred", "score" => 10); a[1] = array("value" => "john", "score" => 50); a[2] = array("value" => "paul", "score" => 5); 

i sort "a" array based on "score" value of associated arrays

it become:

a[0] = array("value" => "paul", "score" => 5); a[1] = array("value" => "fred", "score" => 10); a[2] = array("value" => "john", "score" => 50); 

can please me?

you need use usort , comparison function.

something like:

function cmp($a, $b) {     if ($a['score'] == $b['score']) {         return 0;     }     return ($a['score'] < $b['score']) ? -1 : 1; } 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -