Jump to content

help making number ranges with different steps


coolguydudeman

Recommended Posts

Thanks for the reply mjdamato - I apologise for the bad explanation, I would like PHP to automatically create a number sequence starting at 1 and finishing at 30 with a step order of 11, 7, 11 without storing any information in arrays, I was thinking a for loop, but my attempts havent proven sucessful.

Link to comment
Share on other sites

Thanks for the reply mjdamato - I apologise for the bad explanation, I would like PHP to automatically create a number sequence starting at 1 and finishing at 30 with a step order of 11, 7, 11 without storing any information in arrays, I was thinking a for loop, but my attempts havent proven sucessful.

 

Hmm... I guess I understand now. But, as Pikachu stated you would obviously need to to something with the values. Anyway, here is a simple loop to do as you ask. I've made it very flexible so you can change the parameters as needed. THis just echos the values to the page, but you can do with it what you want.

//User configurable values
$value = 1;  //The start value
$maxValue = 30; ??The maximum value before the loop will exit
$stepValues = array(11, 7); //The values to be added on each step, you can add more values - will repeat

//Non user configurable value
$step = 0;

//The loop
while($value <= $maxValue)
{
    echo "{$value}<br />\n";
    $value += $stepValues[$step++%count($stepValues)];
}

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.