0
0

More than 3 years have passed since last update.

数字を指定の桁数に整える

Last updated at Posted at 2020-01-13

記法

書式
str_pad(対象文字列,埋める桁数,埋める文字列,埋める辺)

第一引数:0埋めの対象となる文字列
第二引数:埋める桁数
第三引数:埋める文字
第四引数:左を埋める場合はSTR_PAD_LEFT、右を埋める場合はSTR_PAD_RIGHT、両側を埋める場合はSTR_PAD_BOTHを指定します。実際にコードを書くとなると下記のようになります。

サンプルコード

Sample.php

$CountOfFiles=100;
for($i=1;$i<$CountOfFiles;$i++){
    echo str_pad($i, 2, 0, STR_PAD_LEFT);
}

結果

結果
$ sample.php
001
002
003
004
...

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0