php复杂的编号计算

时间:2016-07-19 06:52:54

标签: php

我有一个明显可变的orderId。

我需要根据它计算另一个9位数字。

示例:

$orderId = 100;

$path should be = 0000000100;

----
$orderId = 2350;

$path should be = 0000002000;


--- 
$orderId = 7500;

$path should be = 0000007000;

提前多多感谢!

1 个答案:

答案 0 :(得分:2)

试试这个

 <?php
  $test = strval(7001);
  echo substr_replace(str_pad("",9,"0"),$test[0],(strlen($test)-1)*(-1),0);
?>

点击此处:https://eval.in/607614

另一种方式是

<?php
$test = 658;
$length = 10-strlen($test);
$str_pad = "0000000000";
$str_pad[$length] = strval($test)[0];
echo $final = $str_pad
?>

点击此处:https://eval.in/607610