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 110 views
1 answer 115 views
1 answer 106 views
1 answer 111 views
1 answer 132 views
1 answer 119 views
1 answer 124 views
...