-2
I want to do a function that generates a string in alphanumeric format ( XXXXXX-XXXXXX ) and did the following function for such:
private static function generateCode() {
function generate() {
$alphaNumeric = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; // ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
$code = '';
for ($i = 0; $i < 6; $i++) {
$code .= $alphaNumeric[ rand(0,strlen($alphaNumeric) - 1) ];
}
return $code; // ex: X0XX0X
}
return sprintf("%s-%s",generate(),generate());
}
However I cannot use generate(), as I do to have this function inside the other?
I think it works well: https://ideone.com/7MRHUm
– Maniero