如何在PHP整数中保持前导零 [英] How to keep leading zeros in PHP integer

查看:101
本文介绍了如何在PHP整数中保持前导零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用api,需要将ClientID作为整数传递给它.问题是某些ID以前导0开头.当我将整数传递给API时,PHP切断了前导零,这使得ClientID不准确.我尝试将ID作为字符串传递以保持零,但API需要一个整数.

I am working with an api and need to pass it the ClientID as an integer. The problem is that some of the ID's start with leading 0's. When I pass the integer to the API...PHP is cutting off the leading zero's which makes the ClientID inaccurate. I have tried passing the ID as a string to keep the zero's but the API expects an integer.

示例:当我将ClientID = 00061423传递给API时,它会缩短为61423,导致请求失败,因为它找不到该客户端.

Example: ClientID = 00061423 when I pass it to the API it gets shortened to 61423 leading the request to fail because it can't find that client.

有没有一种方法可以让PHP在整数上保留前导零?

Is there a way to have PHP keep the leading zero's on integers?

推荐答案

您不能在整数中保留前导零.您可以在输出时使用sprintf()str_pad()等将它们保存在 string add 中.

You cannot keep leading zeros in integer. You can either keep them in a string or add at output time, using sprintf(), str_pad(), etc.

这篇关于如何在PHP整数中保持前导零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆