Mic*_*und 36 php arrays sorting
如何对数组进行排序: $array[$i]['title'];
数组结构可能如下:
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');
Run Code Online (Sandbox Code Playgroud)
那么数据是否基于数组中的标题字段以ASC顺序显示?
mea*_*gar 100
usort
为此目的明确构建的用法.
function cmp($a, $b)
{
return strcmp($a["title"], $b["title"]);
}
usort($array, "cmp");
Run Code Online (Sandbox Code Playgroud)