Question : How to avoid zero(s) in front of number(s) disappears in array

Hi experts...
I included my simplified codes below.

Straight to the example so you can get a better view for this case :

Let say I have $data = '1-5';
and my code turns it correctly into:
1
2
3
4
5

But if I have $data = '01-05';
then my code turns it into (not correct, not what I want):
01
2
3
4
5

... where the correct result (that I want) should be :
01
02
03
04
05

And the results are always not correct if I have :
$data = '01-05';
or...
$data = '0021-0025';
or maybe...
$data = '000101-000108';

So, seems like zero(s) in front of the numbers are disappear.. only the top/first array that is displayed correctly.

Any advance help for this case please ...
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
<?php

$data = '1-5';
//$data = '01-05';
//$data = '0021-0025';
//$data = '000101-000108';

	list($start_at, $end_at) = split('-', $data); 

	$arr_data = ''; 
	for ($i = $start_at; $i <= $end_at; $i++) 
		{
			$arr_data .= $i.'<br>';
		}

echo $arr_data;

?>

Answer : How to avoid zero(s) in front of number(s) disappears in array

Sorry, after posting the above I decided I had mis-read the question and that the snippet below is nearer what you need.

It's obviously too late here.....  :-(

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
<?php

$data = '1-5';
$data = '01-05';
$data = '0021-0025';
$data = '000101-000108';

     list($start_at, $end_at) = split('-', $data); 
     $formatStr = "%0" . strlen($start_at) . "d";

     $arr_data = ''; 
     for ($i = intval($start_at); $i <= intval($end_at); $i++) 
          {
               $arr_data .= sprintf( $formatStr, $i ).'<br>';
          }

echo $arr_data;

?>
Random Solutions  
 
programming4us programming4us