We help IT Professionals succeed at work.
Get Started

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

trrsrr
trrsrr asked
on
389 Views
Last Modified: 2013-12-12
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 ...
<?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;

?>

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE