PHP number format

Say I have the number 5

I want it to display 005

Say I have the number 82

I want it to display 082

Say I have the number 726

I want it to display 726

How do I format a variable so it shows as 3 integers?

$no_len = strlen($number);

if($no_len == '1')
	$display_no = '00'.$number;
elseif($no_len == '2')
	$display_no = '0'.$number;
	$display_no = $number;

Thank you, I am already doing it this way somewhat, I was just wondering if there was already a premade function for doing it.

Is there?

yes, a lot.
not only for the number formatting, but for many other things.
I’d suggest you to take brief look at php strings functions,
you will find one you need and also many other useful things you can use in the future

Take a look at [fphp]strpad/fphp and also look closely at how [fphp]sprintf/fphp works too.

Bear in mind now that PHP may still interpret 05 to mean 5 or it may not, so be careful what else you do with it.

[edit]Actually 010 is a probably a better example of what can go wrong

var_dump( 010 );

gives : integer 8

I’m only using it to echo values, not insert values… so it should be fine.