- print_r: documentation ( source)
- random_int: documentation ( source)
- sprintf: documentation ( source)
<?php
function makeCodes($numCodes, $codeLength) {
$digits = '01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$codes = [];
$nextCode = 0;
for ($i = 0; $i<$numCodes; $i++) {
$code = '';
for ($j = 0; $j<$codeLength-3;$j++) {
$code .= $digits[random_int(0,strlen($digits)-1)];
}
$codes[] = sprintf('%s%03X', $code, $nextCode);
$nextCode++;
}
return $codes;
}
print_r(makeCodes(10, 24));