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 228 views
1 answer 237 views
2 answers 295 views
2 answers 254 views
1 answer 215 views
215 views asked May 26, 2024 by avibootz
2 answers 277 views
277 views asked May 26, 2024 by avibootz
2 answers 287 views
...