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?
Use usort
which is built explicitly for this purpose.
function cmp($a, $b)
{
return strcmp($a["title"], $b["title"]);
}
usort($array, "cmp");
usort($domain_array, function ($a, $b)
{
return strcmp($a["name"], $b["name"]);
});
Gabi Lee 2016-10-11 08:35