Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我尝试了我在这里找到的接受的答案,但如果数字像 -9、-8、-7 等,接受的答案不会添加前导零。
如果一个数字在这两种情况下都是单个数字,如果是正数或负数,我想附加一个零,
+9 => +09 -9 => -09
有什么建议么?
echo sprintf('%+03d', $number);
你可以做这样的事情
function addZero($number) switch(strLen($number)) { case 1: return "0" . $number; break; case 2: if (substr($number, 0) == "-") return "-0" . substr($number, 1); break; } return $number }