just some simple math really 😉
function getIncrement($start, $end, $times) {
$distance = $times - 1;
$increment = ($end - $start) / $distance;
return $increment;
}
Here is function to test it:
function testIncrementLoop($start, $times, $increment) {
for ($i=1; $i<=$times; $i++) {
echo "$i: $start\n";
$start += $increment;
}
}
Here are some tests. (I ran these from the PHP 5 console):
php > echo getIncrement(1000, 4500000, 100);
45444.444444444
php >
php > testIncrementLoop(1000, 100, getIncrement(1000, 4500000, 100));
1: 1000
2: 46444.444444444
3: 91888.888888889
4: 137333.33333333
5: 182777.77777778
6: 228222.22222222
7: 273666.66666667
8: 319111.11111111
9: 364555.55555556
10: 410000
11: 455444.44444444
12: 500888.88888889
13: 546333.33333333
14: 591777.77777778
15: 637222.22222222
16: 682666.66666667
17: 728111.11111111
18: 773555.55555556
19: 819000
20: 864444.44444444
21: 909888.88888889
22: 955333.33333333
23: 1000777.7777778
24: 1046222.2222222
25: 1091666.6666667
26: 1137111.1111111
27: 1182555.5555556
28: 1228000
29: 1273444.4444444
30: 1318888.8888889
31: 1364333.3333333
32: 1409777.7777778
33: 1455222.2222222
34: 1500666.6666667
35: 1546111.1111111
36: 1591555.5555556
37: 1637000
38: 1682444.4444444
39: 1727888.8888889
40: 1773333.3333333
41: 1818777.7777778
42: 1864222.2222222
43: 1909666.6666667
44: 1955111.1111111
45: 2000555.5555556
46: 2046000
47: 2091444.4444444
48: 2136888.8888889
49: 2182333.3333333
50: 2227777.7777778
51: 2273222.2222222
52: 2318666.6666667
53: 2364111.1111111
54: 2409555.5555556
55: 2455000
56: 2500444.4444444
57: 2545888.8888889
58: 2591333.3333333
59: 2636777.7777778
60: 2682222.2222222
61: 2727666.6666667
62: 2773111.1111111
63: 2818555.5555556
64: 2864000
65: 2909444.4444444
66: 2954888.8888889
67: 3000333.3333333
68: 3045777.7777778
69: 3091222.2222222
70: 3136666.6666667
71: 3182111.1111111
72: 3227555.5555556
73: 3273000
74: 3318444.4444444
75: 3363888.8888889
76: 3409333.3333333
77: 3454777.7777778
78: 3500222.2222222
79: 3545666.6666667
80: 3591111.1111111
81: 3636555.5555556
82: 3682000
83: 3727444.4444444
84: 3772888.8888889
85: 3818333.3333333
86: 3863777.7777778
87: 3909222.2222222
88: 3954666.6666667
89: 4000111.1111111
90: 4045555.5555556
91: 4091000
92: 4136444.4444444
93: 4181888.8888889
94: 4227333.3333333
95: 4272777.7777778
96: 4318222.2222222
97: 4363666.6666667
98: 4409111.1111111
99: 4454555.5555556
100: 4500000
php >
I think this is what you are looking for, right?