Всем добрый день.
Сижу, ломаю голову, руки, клавиатуру...
Нужно исходный массив $oldarray такого вида:
$oldarray = Array
(
[0] => Array
(
[DATE] => 01.01.17
[STATE] => высокий
[SUM] => 575355
[PROCENT] => .67
),
[1] => Array
(
[DATE] => 01.01.17
[STATE] => средний
[SUM] => 82031289
[PROCENT] => 96.01
),
[2] => Array
(
[DATE] => 01.01.17
[STATE] => низкий
[SUM] => 2835822
[PROCENT] => 3.32
),
[3] => Array
(
[DATE] => 01.02.17
[STATE] => высокий
[SUM] => 540355
[PROCENT] => .64
),
[4] => Array
(
[DATE] => 01.02.17
[STATE] => средний
[SUM] => 81360189
[PROCENT] => 95.87
),
[5] => Array
(
[DATE] => 01.02.17
[STATE] => низкий
[SUM] => 2964194
[PROCENT] => 3.49
),
[6] => Array
(
[DATE] => 01.03.17
[STATE] => высокий
[SUM] => 560355
[PROCENT] => .66
),
[7] => Array
(
[DATE] => 01.03.17
[STATE] => средний
[SUM] => 81549849
[PROCENT] => 95.88
),
[8] => Array
(
[DATE] => 01.03.17
[STATE] => низкий
[SUM] => 2942863
[PROCENT] => 3.46
)
);
привести к такому виду $newarray:
$newarray = Array
(
[0] => Array
(
[DATE] => 01.01.17
[высокий] => 575355
[высокий процент] => .67
[средний] => 82031289
[средний процент] => 96.01
[низкий] => 2835822
[низкий процент] => 3.32
)
[1] => Array
(
[DATE] => 01.02.17
[высокий] => 540355
[высокий процент] => .64
[средний] => 81360189
[средний процент] => 95.87
[низкий] => 2964194
[низкий процент] => 3.49
)
[2] => Array
(
[DATE] => 01.03.17
[высокий] => 560355
[высокий процент] => .67
[средний] => 81549849
[средний процент] => 96.01
[низкий] => 2942863
[низкий процент] => 3.32
)
)
Пробовал что-то типо этого - не решил задачу:
$newarray = array();
for ($i = 0; $i < 3; $i++) {
foreach ($oldarray as $rkey){
$newarray[$i]['DATE'] = $rkey['DATE'];
$newarray[$i][$rkey['STATE']] = $rkey['SUM'];
$newarray[$i][$rkey['PROCENT']] = $rkey['PROCENT'];
}
}
Пожалуйста, помогите