说明:该函数将数字转化字符串并指定字符串长度,长度不够左侧补0。
代码如下:
<?php
/**
 * 数字转为字符串
 * edit www.jb200.com
*/
function num2str($num,$length){
        $num_str = (string)$num;
        $num_strlength = count($num_str);
        if ($length > $num_strlength) {
            $num_str=str_pad($num_str,$length,"0",STR_PAD_LEFT);
        }
        return $num_str;
    }
//调用示例
echo num2str(2,5);
?>