Create Numeric List with PHP by adding 0 from 1 to 99

Asked

Viewed 35 times

2

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

Generates a list as:

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

But how to leave her like this:

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

But only when it has more than 10 numbers, or more than 100

1 answer

2


Using the php str_pad

<?php echo str_pad($count_number++, 2, 0, STR_PAD_LEFT); ?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.