How to check if a number contains identical digits in PHP

1 Answer

0 votes
function isNumberContainIdenticalDigits($num) {
    $str = strval($num);
    
    $set = array_unique(str_split($str));
     
    return count($set) === 1;
}
 
$num = 333333;
 
if (isNumberContainIdenticalDigits($num)) {
    echo "yes";
} else {
    echo "no";
}

 
 
/*
run:
 
yes
 
*/

 



answered Jul 25, 2024 by avibootz

Related questions

1 answer 113 views
1 answer 100 views
1 answer 107 views
1 answer 108 views
1 answer 111 views
1 answer 96 views
1 answer 115 views
...