trrsrr
asked on
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 ...
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;
?>
The code didn't attach properly.
<?php
$data = '1-5';
//$data = '01-05';
//$data = '0021-0025';
//$data = '000101-000108';
list($start_at, $end_at) = split('-', $data);
$arr_data = '';
for ($i = intval($start_at); $i <= intval($end_at); $i++)
{
$arr_data .= $i.'<br>';
}
echo $arr_data;
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@bportlock:
I believe you got my point wrong, I dont want to remove all available zero(s) ... I want those available zero(s) to appears.
So, for example I have $data = '000101-000105';
Then the result should be:
000101
000102
000103
000104
000105
while your codes will give me this result:
101
102
103
104
105
I believe you got my point wrong, I dont want to remove all available zero(s) ... I want those available zero(s) to appears.
So, for example I have $data = '000101-000105';
Then the result should be:
000101
000102
000103
000104
000105
while your codes will give me this result:
101
102
103
104
105
ASKER
Ha ha ... u're cool man.
Thanks for the revised codes. It's awesome... ^_^
Thanks for the revised codes. It's awesome... ^_^
Hey - glad it's OK for you. I'm off for a good night's kip.
Good luck with your code & project.
Good luck with your code & project.
http://www.php.net/intval