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 221 views
1 answer 229 views
2 answers 288 views
2 answers 247 views
1 answer 209 views
209 views asked May 26, 2024 by avibootz
2 answers 268 views
268 views asked May 26, 2024 by avibootz
2 answers 283 views
...