日期:2014-05-17 浏览次数:20513 次
$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.'<br />';// }
$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.'<br />';// }