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 227 views
1 answer 236 views
2 answers 293 views
2 answers 252 views
1 answer 215 views
215 views asked May 26, 2024 by avibootz
2 answers 274 views
274 views asked May 26, 2024 by avibootz
2 answers 287 views
...