1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| <?php
function parts($start, $end, $parts) {
// Find what our actual length is:
$length = $end - $start;
do {
$start += $length / $parts;
yield $start;
} while ($start < $end);
}
// Break 5 feet into 3 parts:
foreach (parts(0, 5, 3) as $l) {
echo $l, " ";
}
echo "\n";
// Break the range 10-90 into 12 parts:
foreach (parts(10, 90, 12) as $l) {
echo $l, " ";
}
echo "\n";
|