PHP判断单双

 /**
     * 判断单双
     * 1为单,0为双
     * @param  array|integer $numbers 
     * @return int
     */
    public function judgeSingDual($numbers){
        if(is_array($numbers)){
            $total=0;
            foreach ($numbers as $n){
                $total+=intval($n);
            }
            if($total%2==0){
                return 0;
            }else{
                return 1;
            }
        }else{
            if($numbers%2==0){
                return 0;
            }else{
                return 1;
            }
        }

    }
 


分类: PHP 点赞(0) 收藏

评论