How to check if a string contains identical digits in PHP

1 Answer

0 votes
function isStringContainIdenticalDigits($str) {
    $set = array_unique(str_split($str));
    
    return count($set) === 1;
}

$str = "8888888";

if (isStringContainIdenticalDigits($str)) {
    echo "yes";
} else {
    echo "no";
}




/*
run:

yes

*/

 



answered Jul 24, 2024 by avibootz

Related questions

1 answer 116 views
1 answer 122 views
1 answer 112 views
1 answer 127 views
1 answer 144 views
1 answer 126 views
1 answer 131 views
...