$id = implode('-', array_map(function($n) { return sprintf('%02d', mt_rand(0, 99)); }, array_fill(0, 6, 0)));
It works fine and can be put all on one line (although a 109 char line) but realistically should be split for readability as I find it quite incomprehensible. Maybe:
$id = implode('-', array_map( function($n) { return sprintf('%02d', mt_rand(0, 99)); }, array_fill(0, 6, 0) ));
Whilst that was interesting, in the end I used a more conventional approach (for readability and maintainability):
$numbers = array(); while (count($numbers) < 6) { $numbers[] = sprintf('%02d', mt_rand(0, 99)); } $id = implode('-', $numbers);
No comments:
Post a Comment