Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. I check, compile and run every program. Contact me at: aviboots(AT)netvision.net.il

Hostgator - Save 50% Off Your New Optimized WordPress Hosting With Coupon: WDA50

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Dedicated Hosting Superb Internet

simplilearn big data and analytics

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Buy Cool Shirts

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


6,300 questions

8,938 answers

573 users

How to check qualify as unique number that must contain one of each digit up to the length of himself in PHP

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial


10 views
asked Sep 4 by avibootz
edited Sep 4 by avibootz

2 Answers

0 votes
function is_unique_digital($number, $zero=false)
{
    $number = str_split($number);
    sort($number);
     
    return implode($number) === substr('0123456789', !$zero, count($number));
}

if (is_unique_digital("12342"))
    echo "1. true<br/>";
else
    echo "1. false<br/>";

if (is_unique_digital("1142"))
    echo "2. true<br/>";
else
    echo "2. false<br/>";
    
if (is_unique_digital("1342"))
    echo "3. true<br/>";
else
    echo "3. false<br/>";
 
if (is_unique_digital("13042", true))
    echo "4. true<br/>";
else
    echo "4. false<br/>";
    
if (is_unique_digital("1042", true))
    echo "5. true<br/>";
else
    echo "5. false<br/>";
    
if (is_unique_digital("16345"))
    echo "6. true<br/>";
else
    echo "6. false<br/>";

if (is_unique_digital("162345"))
    echo "7. true<br/>";
else
    echo "7. false<br/>";

 
/*
run: 
  
1. false
2. false
3. true
4. true
5. false
6. false
7. true
  
*/ 

 




answered Sep 4 by avibootz
edited Sep 4 by avibootz
0 votes
function is_unique_digital($number)
{
    $number = str_split($number);
    sort($number);
    
    $start = 1;
    if ("0" === $number[0])
        $start = 0;
    
    return implode($number) === substr('0123456789', $start, count($number));
}

if (is_unique_digital("12342"))
    echo "1. true<br/>";
else
    echo "1. false<br/>";

if (is_unique_digital("1142"))
    echo "2. true<br/>";
else
    echo "2. false<br/>";
    
if (is_unique_digital("1342"))
    echo "3. true<br/>";
else
    echo "3. false<br/>";
 
if (is_unique_digital("13042"))
    echo "4. true<br/>";
else
    echo "4. false<br/>";
    
if (is_unique_digital("1042"))
    echo "5. true<br/>";
else
    echo "5. false<br/>";
    
if (is_unique_digital("16345"))
    echo "6. true<br/>";
else
    echo "6. false<br/>";

if (is_unique_digital("162345"))
    echo "7. true<br/>";
else
    echo "7. false<br/>";

 
/*
run: 
  
1. false
2. false
3. true
4. true
5. false
6. false
7. true
  
*/   

 




answered Sep 4 by avibootz
...