How to add 0 in front of number in PHP?

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

How to add 0 in front of number in PHP?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by dmitrypro77 , 7 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);