How to check if a number is a repdigit number (a natural number composed of repeated digits) in PHP

1 Answer

0 votes
function isRepdigitNumber($num) {
    $array = str_split(strval($num));
 
    $combine = array_combine($array, $array);
 
    return count($combine) == 1;    
}

$num = 8888888;
   
if (isRepdigitNumber($num)) {
    echo "yes";
} else {
    echo "no";
}

 
 
/*
run:
   
yes
   
*/

 



answered Feb 7, 2024 by avibootz
...