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 133 views
1 answer 142 views
2 answers 166 views
2 answers 153 views
1 answer 134 views
134 views asked May 26, 2024 by avibootz
2 answers 144 views
144 views asked May 26, 2024 by avibootz
2 answers 176 views
...