|
@@ -675,9 +675,9 @@ class PVPProc {
|
|
|
}
|
|
|
|
|
|
|
|
|
- $bPlayerUIDs = self::Array_Rand($bPlayerUIDs, 1);
|
|
|
- $mPlayerUIDs = self::Array_Rand($mPlayerUIDs, 2);
|
|
|
- $aPlayerUIDs = self::Array_Rand($aPlayerUIDs, 2);
|
|
|
+ $bPlayerUIDs = self::array_random_assoc($bPlayerUIDs, 1);
|
|
|
+ $mPlayerUIDs = self::array_random_assoc($mPlayerUIDs, 2);
|
|
|
+ $aPlayerUIDs = self::array_random_assoc($aPlayerUIDs, 1);
|
|
|
|
|
|
$uidWithScore = array_merge($bPlayerUIDs, $mPlayerUIDs, $aPlayerUIDs); # 合并为玩家列表
|
|
|
|
|
@@ -685,25 +685,24 @@ class PVPProc {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 数组随机
|
|
|
+ * 随机关联数组
|
|
|
* @param type $arr
|
|
|
- * @param type $intNum
|
|
|
- */
|
|
|
- static function Array_Rand($arr, $intNum = 0) {
|
|
|
- $ret = (array) $arr;
|
|
|
- if (is_array($ret)) {
|
|
|
- $brd = shuffle($ret);
|
|
|
- if (!$brd) {
|
|
|
- die("shuffle 失败");
|
|
|
- }
|
|
|
- if ($intNum > 0) {
|
|
|
- if ($intNum < count($ret)) {
|
|
|
- $ret = array_slice($ret, 0, $intNum);
|
|
|
- }
|
|
|
- }
|
|
|
- return $ret;
|
|
|
+ * @param type $num
|
|
|
+ * @return type
|
|
|
+ */
|
|
|
+ function array_random_assoc($arr, $num = 1) {
|
|
|
+ $keys = array_keys($arr);
|
|
|
+ shuffle($keys);
|
|
|
+
|
|
|
+ if ($num > count($arr)) {
|
|
|
+ $num = count($keys);
|
|
|
}
|
|
|
- return $arr;
|
|
|
+
|
|
|
+ $r = array();
|
|
|
+ for ($i = 0; $i < $num; $i++) {
|
|
|
+ $r[$keys[$i]] = $arr[$keys[$i]];
|
|
|
+ }
|
|
|
+ return $r;
|
|
|
}
|
|
|
|
|
|
/**
|