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

PHP determines half straight, straight, and pair example code

小云云
Release: 2023-03-21 18:28:01
Original
3036 people have browsed it

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;
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template