【发布时间】:2011-08-30 09:01:45
【问题描述】:
我正在创建一个彩票来配对人们。所以我想要一种方法来洗牌数组中的字符串,其中没有项目最终在同一个地方。 (你不能和自己配对)
public function shuffleSantas(){
$query = $this->db->get('person');
$givers = array();
$recievers = array();
foreach($query->result() as $row):
$givers[] = $row->name;
//here i want a random order, but no name can be on the same place as in $givers!
$recievers[] = '';
endforeach;
【问题讨论】:
-
也许你可以让 1 个大数组对其进行 shuffle() 并将其分成两半?
-
你可能想看看
array_rand()。