我有一个明显可变的orderId。
我需要根据它计算另一个9位数字。
示例:
$orderId = 100;
$path should be = 0000000100;
----
$orderId = 2350;
$path should be = 0000002000;
---
$orderId = 7500;
$path should be = 0000007000;
提前多多感谢!
答案 0 :(得分:2)
试试这个
<?php
$test = strval(7001);
echo substr_replace(str_pad("",9,"0"),$test[0],(strlen($test)-1)*(-1),0);
?>
另一种方式是
<?php
$test = 658;
$length = 10-strlen($test);
$str_pad = "0000000000";
$str_pad[$length] = strval($test)[0];
echo $final = $str_pad
?>