Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何以特定图案打印数字?_Php - Fatal编程技术网

Php 如何以特定图案打印数字?

Php 如何以特定图案打印数字?,php,Php,我有一个整数模式(0000012019)。其中2019年为本年度,000001需要随着插入db的每一行而增加,如000002、000003、000004、000005等。 我怎样才能做到这一点呢?首先,这是你的一根弦。 您可以使用substr()拆分字符串,并对第一部分进行计算,然后使用str_pad从左侧填充0,将其转换回字符串 $str = '0000012019'; $first = substr($str, 0, 6); $year = substr($str, -4); $firs

我有一个整数模式(0000012019)。其中2019年为本年度,000001需要随着插入db的每一行而增加,如000002、000003、000004、000005等。
我怎样才能做到这一点呢?

首先,这是你的一根弦。
您可以使用substr()拆分字符串,并对第一部分进行计算,然后使用str_pad从左侧填充0,将其转换回字符串

$str = '0000012019';
$first = substr($str, 0, 6);
$year = substr($str, -4);


$first = str_pad($first+1, 6, 0, STR_PAD_LEFT);
$new = $first . $year;
echo $new; // 0000022019

你写过代码吗?你能和我们分享一下吗?不,我没有,我不知道从哪里开始@powerPixiethis工作。谢谢你,安德烈亚斯