如何重置PHP中的特定值


How to reset the specific values in PHP

我有一个类似115040026的值。例如,第一个数字从1开始,该值希望递增115040026,115040027,115040028,依此类推

如果值从215040029开始,我现在不想要增量值,我的结果是这样的215040029,但我的预期输出是215040001

如果我更改第一个数字序列,我想用01,02..等开头重置最后一位数字。

+--------+-----------+
| Server | Port      |
+--------+-----------+
| 1      | 115040027 |
| 2      | 115040028 |
| 3      | 115040029 |
| 4      | 215040001 |
+--------+-----------+

当我通过$this->mynumber('30', "1");时,我的下一个号码将是115040030

如果我通过这个$this->mynumber('30', "2");,我的下一个号码应该是215040001

如果215040001已经存在,我的输出将是215040002

我试过的是

 $this->mynumber('29', "1");
 private function mynumber($no, $comid)
     {
         $current_year  = substr(date("Y"), -2); //Get Last Two Digits
         $current_month = date("m");
         $company       = $comid;
         $orderno_len   = strlen($no);
         switch($orderno_len)
         {
             case 1:
             $value = "000".$no;
             break;
             case 2:
             $value = "00".$no;
             break;
             case 3:
             $value = "0".$no;
             break;
             default:
             break;
         }

         return $company.$current_year.$current_month.$value;
     }

尝试"modulo"-如果您希望最大值为30,请使用
$number = $number%30
示例:
0%30=0
1%30=1
29%30=29
30%30=0
31%30=1