How to put 0 before single number in PHP

Home Forums PHP How to put 0 before single number in PHP

Tagged: ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1400
    Munia I.
    Participant

    I’m running foreach() loop and into my application and there is a number incrementing. I want to put 0 (zero) before single number like 01 to 09. How to I can do that?

    #1402
    Mofizul
    Keymaster

    I have used the code: <?= str_pad($i, 2, 0, STR_PAD_LEFT) ?>

    Here is the explanation of the code: str_pad(($input, $pad_length, $pad_string = " ", $pad_type = STR_PAD_RIGHT))

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.