1 <?php 2 3 namespace AppHttpControllers; 4 5 use AppHttpmodelpoker; 6 use IlluminateHttpRequest; 7 8 9 class PokerController extends Controller 10 11 { 12 //总方法 13 public function gets(){ 14 15 $model = new poker(); 16 17 $res = $model->select(); 18 19 //循环合并一维数组 20 foreach ($res as $k => $v){ 21 22 $arr[$k] = $v['num']; 23 24 } 25 26 shuffle($arr); 27 28 29 $resd = $this->Fplayer($arr); 30 31 $resJ = $this->Jplayer($resd); 32 33 var_dump($resJ); 34 35 36 } 37 38 //随机洗牌方法 39 public function Xplayer($res){ 40 41 return shuffle($res); 42 43 } 44 45 //随机发牌 46 public function Fplayer($arr){ 47 48 for ($i=0;$i<=51;$i+=4){ 49 50 $nums['0'][] = $arr[$i]; 51 $nums['1'][] = $arr[$i+1]; 52 $nums['2'][] = $arr[$i+2]; 53 $nums['3'][] = $arr[$i+3]; 54 } 55 return $nums; 56 57 } 58 //解析每个用户的牌 59 public function Jplayer($resd){ 60 61 foreach ($resd as $k => $v){ 62 63 foreach ($v as $kk => $vv){ 64 65 66 $n = substr($vv,-2,1); 67 if($n==0){ 68 $pop = substr($vv,-1); 69 }else{ 70 $pop = substr($vv,-2); 71 } 72 if($vv <= 113){ 73 74 $arr[$kk] = '黑桃'."$pop"; 75 76 }elseif($vv <= 213){ 77 $arr[$kk] = '红桃'.$pop; 78 }elseif ($vv <= 313){ 79 $arr[$kk] = '梅花'.$pop; 80 }elseif($vv <= 413){ 81 $arr[$kk] = '方片'.$pop; 82 } 83 } 84 $arrs[$k] = $arr; 85 86 } 87 return $arrs; 88 89 } 90 }