Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pad counter with leading 0 up to 9, then remove leading zero with php

Tags:

php

printf

count

Trrying to pad with leading 0's up to 9, then remove.

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

So far I have this:

<?php  $value = $count++;
printf("%02d", $value);
?>
like image 636
jrutter Avatar asked Dec 16 '22 00:12

jrutter


1 Answers

You can also use str_pad()

<?php  
    $value = $count++;
    echo str_pad($value, 2, "0", STR_PAD_LEFT);
?>
like image 185
John Conde Avatar answered Dec 28 '22 07:12

John Conde