-3

I would like to generate an auto increment invoice number using prefix.

Digits: 11 Prefix: B

From: B0000000001 to B0000000020.

Is there a easy way to do this in PHP?

Dany Bullet
  • 1
  • 1
  • 2
  • 3
    What have you tried? str_pad and concatenation should make this pretty simple in php. – Devon Jun 13 '18 at 16:09

1 Answers1

0

This is how you can do in in php.

$index = 11;
$prefix = 'B';
echo sprintf("%s%011s", $prefix, $index);
Jason K
  • 1,386
  • 1
  • 9
  • 15
  • `echo sprintf()` is an "antipattern". There is absolutely no reason that anyone should ever write `echo sprintf()` -- it should be `printf()` without `echo` every time. – mickmackusa Apr 16 '22 at 03:21