Create Numeric List with PHP adding 0 from 1 to 99 [duplicate]

2

$cont = 1;
<?php echo $cont++ ?>:

Generate a list like:

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ...

But how to leave it like this:

01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12 ...

But only when you have more than 10 numbers, or more than 100

    
asked by anonymous 18.11.2018 / 17:05

1 answer

2

Using php's str_pad

<?php echo str_pad($count_number++, 2, 0, STR_PAD_LEFT); ?>
    
18.11.2018 / 17:31