Reputation: 23
I have an orderId which obviously is variable.
I need to compute another 9 digit number based on that.
Example:
$orderId = 100;
$path should be = 0000000100;
----
$orderId = 2350;
$path should be = 0000002000;
---
$orderId = 7500;
$path should be = 0000007000;
Thanks a lot in advance!
Upvotes: 0
Views: 74
Reputation: 34914
Try like this
<?php
$test = strval(7001);
echo substr_replace(str_pad("",9,"0"),$test[0],(strlen($test)-1)*(-1),0);
?>
Check here : https://eval.in/607614
Another way is
<?php
$test = 658;
$length = 10-strlen($test);
$str_pad = "0000000000";
$str_pad[$length] = strval($test)[0];
echo $final = $str_pad
?>
Check here : https://eval.in/607610
Upvotes: 2