Jump to content

[SOLVED] adding 0 to numbers


drisate

Recommended Posts

works but my code is not ... i am trying to increment 2 numbers and for some reason they both return 000 and 0000

 

WHILE ($counter1 < 1000){

$counter1 = str_pad((int) $counter1,3,"0",STR_PAD_LEFT);

 

WHILE ($counter2 < 1000){

$counter2 = str_pad((int) $counter2,4,"0",STR_PAD_LEFT);

echo $counter1."-".$counter2;

$counter2++;

}

 

$counter1++;

}

works but my code is not ... i am trying to increment 2 numbers and for some reason they both return 000 and 0000

 

WHILE ($counter1 < 1000){

$counter1 = str_pad((int) $counter1,3,"0",STR_PAD_LEFT);

 

WHILE ($counter2 < 1000){

$counter2 = str_pad((int) $counter2,4,"0",STR_PAD_LEFT);

echo $counter1."-".$counter2;

$counter2++;

}

 

$counter1++;

}

 

with what i think you want to do, try something like this..

 

WHILE ($counter1 < 1000){
   WHILE ($counter2 < 1000){
      echo str_pad((int) $counter1,5,"0",STR_PAD_LEFT)."-".str_pad((int) $counter2,5,"0",STR_PAD_LEFT);
      $counter2++;
   }
$counter1++;
}

 

also, since your counter2 does not reset... you're  never going to really get to run through all the values i'm suspecting you were meaning to... maybe you want to put $counter2 = 1; directly between the two loop statements.... going to make a huge list of numbers... also, i'm guessing you'll want a line break or else it will just run all together

Yeah it's almost that. I am trying to get 1000 times 1000 the double loop you gave me never increments the seconde loop

 

00000-00001

00000-00002

00000-00003

00000-00004

[...]

00000-00999

 

i need it to start over the loop with

00002-00001

 

and so on untile i get

00999-00999

well this is if you want to go from 1-1 to 1-999 and then 2-1 to 2-999 etc... seperated with a <br />... i'm sure you can figure out where to go from here if you want to change the initial values or something.

$counter1 = 1;
WHILE ($counter1 < 1000){
   $counter2 = 1;
   WHILE ($counter2 < 1000){
      echo str_pad((int) $counter1,5,"0",STR_PAD_LEFT)."-".str_pad((int) $counter2,5,"0",STR_PAD_LEFT)."<br />";
      $counter2++;
   }
$counter1++;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.