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

Possible Duplicate:
how to sort a multidemensional array by an inner key
How to sort an array of arrays in php?

How can I sort an array like: $array[$i]['title'];

Array structure might be like:

array[0](
'id' => 321,
'title' => 'Some Title',
'slug' => 'some-title',
'author' => 'Some Author',
'author_slug' => 'some-author');

array[1](
'id' => 123,
'title' => 'Another Title',
'slug' => 'another-title',
'author' => 'Another Author',
'author_slug' => 'another-author');

So data is displayed in ASC order based off the title field in the array?

share|improve this question
Michael: Tim was just being helpful. Searching first is a bit of a prerequisite here, and we get a lot of questioners that don't appear to have searched/tried first. – halfer Apr 3 '12 at 19:39
add comment (requires an account with 50 reputation)

marked as duplicate by Tim Cooper, Paulpro, meagar, Robert Harvey Apr 3 '12 at 19:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 1 down vote accepted

Use usort which is built explicitly for this purpose.

function cmp($a, $b)
{
    return strcmp($a["title"], $b["title"]);
}

usort($array, "cmp");
share|improve this answer
add comment (requires an account with 50 reputation)

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