时间:2021-07-01 10:21:17 帮助过:18人阅读
$json = '[{"name":"a1"},{"name":"a10"},{"name":"a12"},{"name":"a3"},{"name":"a5"},{"name":"b21"},{"name":"b2"},{"name":"b11"}]'; natsort($json); $data = json_decode($json); foreach ($data as $row) { echo $row->name.'
';// }
$json = '[{"name":"a1"},{"name":"a10"},{"name":"a12"},{"name":"a3"},{"name":"a5"},{"name":"b21"},{"name":"b2"},{"name":"b11"}]'; $data = json_decode($json); usort($data, 'cmp'); function cmp($a, $b) { if ($a->name == $b->name) return 0; return $a->name > $b->name ? 1 : -1; } foreach ($data as $row) { echo $row->name.'
';// }