Home  >  Article  >  Backend Development  >  PHP determines half straight, straight, and pair example code

PHP determines half straight, straight, and pair example code

小云云
小云云Original
2018-03-20 10:58:062963browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn