Created
August 2, 2017 09:11
-
-
Save obojdi/cbb9d4a44b39920cc90af756d22606e8 to your computer and use it in GitHub Desktop.
random username checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dbh = ['user_10', 'user_02', 'user_05', 'user_08', 'user_07', 'user_06', 'user_09']; | |
$a = function ($un = '') use ($dbh, &$a){ | |
$random_digit = sprintf("%02d", rand(0, 10)); | |
$username_random = "user_" . $random_digit; | |
if(strlen($un)){ | |
$username = $un; | |
}else{ | |
$username = $username_random; | |
} | |
if(in_array($username, $dbh)){ | |
// username exists, check again | |
echo $username . ' exists '; | |
return $a(); | |
}else{ | |
// username does not exist, use it | |
echo ' use $username '; | |
return $username; | |
} | |
}; | |
$b = $a(); | |
echo $b; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment