I'd like to convert this array:
Array
(
[5] => 3.5
[6] => 4.5
[7] => 5.5
)
Array
(
[8] => 5
[9] => 6
[10] => 7
)
Into a two-dimensional array that would look like this:
$array = array(
"a" => array("3.5","4.5", etc.),
"b" => array("5","6", etc.),
);
I think I'm getting close with the following code, but I'm still missing a name such as "a" and "b" for each array group:
$array = array($result);
echo '<pre>';
print_r(array_chunk($array,2, true));
echo '</pre>';
Here is the code from where I'm getting the two arrays :
$period = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
$sma = array(6,9);
foreach ($sma as $range) {
$sum = array_sum(array_slice($period, 0, $range));
$result = array($range - 1 => $sum / $range);
for ($i = $range, $n = count($period); $i != $n; ++$i) {
$result[$i] = $result[$i - 1] + ($period[$i] - $period[$i - $range]) / $range;
}
$array = array($result);
echo '<pre>';
print_r(array_chunk($array,2, true));
echo '</pre>';
}