每次在php中插入新数据时,求和一个字符串

每次在php中插入新数据时,求和一个字符串

问题描述:

I have a variable(database column value) which value is look like below.

ALI-0001

now i wanna auto increment this code like ALI-0002, ALI-0003,ALI-0004,ALI-0005 every time i insert new data. I tried the following code.

$project_code = $a[0]->project_code;
$integer = (integer) substr($max_issue_number, 4);
$sum = $integer+1;
$issue_number = $project_code.'-000'.$sum;

我有一个变量(数据库列值),其值如下所示。 p>

ALI-0001 strong> p>

现在我想自动增加此代码,例如 ALI-0002 strong>, ALI-0003 , ALI-0004 strong>, ALI-0005 strong>。 我尝试了以下代码。 p>

   $ project_code = $ a [0]  - > project_code; 
 $ integer =(整数)substr($ max_issue_number,4); 
 $ sum = $ integer + 1; 
 $ issue_number = $ project_code。  '-000'。$ sum; 
  code>  pre> 
  div>

Your solution is str_pad ref: http://php.net/manual/en/function.str-pad.php

So your code should be as below:

$issue_number = $project_code.'-'.str_pad($sum, 4, '0', STR_PAD_LEFT);