Stylish functional code:
function createSeries($min, $max, $interval, $connector) {
return array_map(
function ($num) use ($interval, $connector) {
return implode(' ', array($num, $connector, $num + $interval));
},
range($min, $max - $interval, $interval)
);
}
However, the most efficient way seems to be:
function createSeries($min, $max, $interval, $connector) {
$series = array();
for ($i = $min; $i < $max; $i += $interval) {
$tail = $i + $interval;
$series[] = "$i $connector $tail";
}
return $series;
}
NOTE: PHP is very slow scripting language. You should not mind efficiency extreamly.
1
solved How to create series of set in PHP [closed]