How to Make Number Format like 001,002

Hello Guys Welcome to Coding Gurus Online Portal ...!

You must have noticed your account number is generated at random. It does not match with any of the normal series. The actual fact is the number generated has a series but when displayed it is given a format to make it of a particular lenght and type.

For such situtaions we use codes like the one below. This can be implemented in many cases like generating an ID number for registered users, generating account numbers, displaying docket/ticket numbers and many other activities.

For testing this code in this tutorial, we create 1 file
1.number_format.php

Code 1

<?php
$num = 1;
printf("%04d", $num);
?>
// Result = 0001

Code 2

<?php

// Select your result and assign it to $result.
$result=234;

//Assign your Number Format to $format.
$format='000';

$output= $format . $result;
echo $output;
?>