public function shuffle_assoc($list) { if (!is_array($list)) return $list; $keys = array_keys($list); shuffle($keys); $random = array(); foreach ($keys as $key) $random[$key] = $this->shuffle_assoc($list[$key]); return $random; } public function test(){ $data = array( array("id"=>13,"name"=>"张三"), array("id"=>1,"name"=>"李爱媛"), array("id"=>6,"name"=>"蔡依林"), array("id"=>8,"name"=>"陈思"), array("id"=>21,"name"=>"何达玲"), array("id"=>14,"name"=>"赵勇"), ); $tmp = $this->shuffle_assoc($data); var_dump($tmp);die; } //===============打印结果================ array(6) { [3]=> array(2) { ["id"]=> int(8) ["name"]=> string(6) "陈思" } [5]=> array(2) { ["id"]=> int(14) ["name"]=> string(6) "赵勇" } [1]=> array(2) { ["id"]=> int(1) ["name"]=> string(9) "李爱媛" } [0]=> array(2) { ["name"]=> string(6) "张三" ["id"]=> int(13) } [2]=> array(2) { ["id"]=> int(6) ["name"]=> string(9) "蔡依林" } [4]=> array(2) { ["id"]=> int(21) ["name"]=> string(9) "何达玲" } }