Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想按“名称”对下面的数组进行排序。我已经尝试了几件事,但我无法弄清楚。有什么建议么?
$data = array(); $data[] = array('name'=>'Bill','phone'=>'555-5555'); $data[] = array('name'=>'Joe','phone'=>'555-5554'); ...
您可以使用usort()自定义标准对数组进行排序。
usort()
例如:
function my_sort_by_name($a, $b) { return strcmp($a['name'], $b['name']); } $data = array(); $data[] = array('name'=>'Bill','phone'=>'555-5555'); $data[] = array('name'=>'Joe','phone'=>'555-5554'); usort($data, 'my_sort_by_name');