How to add 0 in front of number in PHP?

Member

arnoldo.moen

by arnoldo.moen, in category: PHP General , 4 months ago

How to add 0 in front of number in PHP?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by dmitrypro77 , 3 months ago

@arnoldo.moen use str_pad() function to add 0 in front of any number in PHP, code:


1
2
3
4
5
6
<?php

$num = 25;

// Output: 025
echo str_pad($num, 3, '0', STR_PAD_LEFT);