Home >Backend Development >PHP Tutorial >PHP determines half straight, straight, and pair example code
This article mainly shares with you the PHP example code for judging half straight, straight, and pair. I hope it can help everyone.
判断半顺,顺子, 对子public function test(){ $var ='1,2,3'; $vars = explode(',',$var); $res = ''; if($vars[0] ==$vars[1] &&$vars[0] ==$vars[2]&& $vars[1] ==$vars[2]){ $res ='豹子'; }else{ $dz =''; if($vars[0] ==$vars[1]){ $dz++; } if($vars[0]==$vars[2]){ $dz++; } if($vars[1] ==$vars[2]){ $dz++; } if($dz ==1){ $res ='对子'; }else { $bb=0; if(abs($vars[0]-$vars[1]) ==1){ $bb++; } if (abs($vars[0]-$vars[2]) ==1){ $bb++; } if(abs($vars[1]-$vars[2]) ==1){ $bb++; } if($bb ==0){ $res ='杂六'; }if($bb==1){ $res ='半顺'; }if($bb==2){ $res ='顺子'; } } } echo $res; }
The above is the detailed content of PHP determines half straight, straight, and pair example code. For more information, please follow other related articles on the PHP Chinese website!