I have a group of numbers I need to put into an array. The numbers start at 0 and increase by 2 for a series of six (e.g. 0, 2, 4, 6, 8, 10) but then jump 26 and the next series continue increasing by 2 (e.g. 36, 38, 40, 42, 44, 46) and on and on. I know I could do the following:
$numArray = array();
$numArray[0] = 0; // starts at 0
$numArray[1] = 2; // increases by 2
$numArray[2] = 4;
$numArray[3] = 6;
$numArray[4] = 8;
$numArray[5] = 10;
$numArray[6] = 36; // increases by 26
$numArray[7] = 38; // then back to increase by 2
$numArray[8] = 40;
$numArray[9] = 42;
$numArray[10] = 44;
$numArray[11] = 46;
$numArray[12] = 72; // increases by 26
$numArray[13] = 74; // then back to increase by 2
$numArray[14] = 76;
$numArray[15] = 78;
$numArray[16] = 80;
$numArray[17] = 82;
and this works fine, but I potentially have hundreds, even thousands of numbers and I don't want to hard code all that.
I've tried the following:
$number = 0;
for ($x=0; $x < 8; $x++)
{
$groupStep = 24; // number to increase by for each group
// Create loop for groups of 6 numbers
$increment = 2; // number to increase each number
$numArray = array();
for($i=0; $i<=5; $i++)
{
$numArray[$i] = $number;
$number = $number + $increment;
}
// Increase by 24 for the next group of 6 answers
$number = $number + $groupStep;
}
And this works but only for display. My array keeps getting started over. I just don't know enough about arrays to figure out what I'm doing wrong. I've searched and searched but haven't been able to find anything. Any assistance or a point to where I can read a solution would be much appreciated.