How to add N zeros to an empty string in PHP

1 Answer

0 votes
$n = 4;
$empty_string = "";

$empty_string = str_pad($empty_string, $n, "0", STR_PAD_LEFT);

echo $empty_string;



/*
run:

0000

*/

 



answered May 26, 2024 by avibootz

Related questions

1 answer 121 views
1 answer 128 views
2 answers 145 views
2 answers 133 views
1 answer 119 views
119 views asked May 26, 2024 by avibootz
2 answers 124 views
124 views asked May 26, 2024 by avibootz
2 answers 154 views
...