PHP保留前导零的数字和
我增加了一些发票号,有前缀和计数器, 假设前缀为PHP保留前导零的数字和,php,laravel,Php,Laravel,我增加了一些发票号,有前缀和计数器, 假设前缀为INV-,计数器以001开头 以下是Laravel中用于自动获取下一个发票号的代码 $lastInv = explode('-', $record->invoice_number); //Gets record and split number $nextInv = $settings->invoice_number_prefix.'-'. ($lastInv[1] + 1); 在这种情况下,数据库中
INV-
,计数器以001
开头
以下是Laravel中用于自动获取下一个发票号的代码
$lastInv = explode('-', $record->invoice_number); //Gets record and split number
$nextInv = $settings->invoice_number_prefix.'-'. ($lastInv[1] + 1);
在这种情况下,数据库中有两条记录,分别为INV-001和INV-002,但使用上述代码,我将获得$nextInv
作为INV-3
如何将下一张发票生成为INV-003
谢谢,您可以使用
str\u pad
将0
与perfix一起使用
像这样
$lastInv=explode('-',$record->invoice\u number)//获取记录和拆分编号
$number=str_pad($lastInv[1]+1,3,“0”,str_pad_左);
$nextInv=$settings->invoice\u number\u prefix.'-'$数量;
注意此处stru pad(“”,3,'0',“”)
此处3是数字,将用零填充,以便您可以根据需要进行调整
参考链接查看