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++;

}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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++;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.