多维PHP数组的基本排序

多维PHP数组的基本排序,php,arrays,sorting,Php,Arrays,Sorting,尝试按名称对数组排序,以便显示字母列表 下面是一段代码: sort($stores); for($i=0; $i<count($stores); $i++) { echo $stores[$i]['name']; } 排序($stores); 对于($i=0;$i使用: 使用: 可以使用自定义比较函数按值对数组进行排序 这里的“自定义”是指自定义对象类型的数组 function compare($a, $b) { return strcmp($a['name'], $b

尝试按名称对数组排序,以便显示字母列表

下面是一段代码:

sort($stores);

for($i=0; $i<count($stores); $i++) {
    echo $stores[$i]['name'];
}
排序($stores);
对于($i=0;$i使用:

使用:

可以使用自定义比较函数按值对数组进行排序

这里的“自定义”是指自定义对象类型的数组

function compare($a, $b)
{
    return strcmp($a['name'], $b['name']);
}

usort($stores, "compare");
可以使用自定义比较函数按值对数组进行排序

这里的“自定义”是指自定义对象类型的数组

function compare($a, $b)
{
    return strcmp($a['name'], $b['name']);
}

usort($stores, "compare");