0
0

str_pad()関数

Last updated at Posted at 2023-12-16

str_pad()関数

第1引数 第2引数 第3引数 第4引数
入力文字列 桁数 埋める文字列 埋め方の形式

第4引数

  • 中寄席
    STR_PAD_BOTH

  • 右寄せ
    STR_PAD_RIGHT

  • 左寄せ
    STR_PAD_LEFT

str_pad()関数
公式マニュアル

実行・結果

$value=Aでそれぞれの場合を試す

//中央寄せ
$value = "A";
$result = str_pad($value, 5, 0, STR_PAD_BOTH);
var_dump($result);
string(5) "00A00" 


//右寄せ
$value = "A";
$result = str_pad($value, 5, 0, STR_PAD_RIGHT);
var_dump($result);
string(5) "0000A"


//左寄せ
$value = "A";
$result = str_pad($value, 5, 0, STR_PAD_LEFT);
var_dump($result);
string(5) "A0000" 
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