~~~ public function index(Request $request) { $weight = 0; $tmp = []; $data = $this->data(); foreach($data as $item){ $weight += $item['weight']; for($i = 0;$i< $item['weight'];$i++){ $tmp[] = $item; } } $use = rand(0,$weight - 1); return $data[$use]; } public function data() { return array( array("id"=>1,"title"=>"语文","weight" => 1), array("id"=>2,"title"=>"数学","weight" => 10), array("id"=>3,"title"=>"英语","weight" => 5), ); } ~~~