How to convert an array in PHP?

Good afternoon everyone.
Sitting, scratching their head, hands, keyboard...

You need the original array $oldarray like this:
$oldarray = Array
(
 [0] => Array
(
 [DATE] => 01.01.17
 [STATE] => high
 [SUM] => 575355
 [PROCENT] => .67
),

 [1] => Array
(
 [DATE] => 01.01.17
 [STATE] => medium
 [SUM] => 82031289
 [PROCENT] => 96.01
),

 [2] => Array
(
 [DATE] => 01.01.17
 [STATE] => low
 [SUM] => 2835822
 [PROCENT] => 3.32
),

 [3] => Array
(
 [DATE] => 01.02.17
 [STATE] => high
 [SUM] => 540355
 [PROCENT] => .64
),

 [4] => Array
(
 [DATE] => 01.02.17
 [STATE] => medium
 [SUM] => 81360189
 [PROCENT] => 95.87
),

 [5] => Array
(
 [DATE] => 01.02.17
 [STATE] => low
 [SUM] => 2964194
 [PROCENT] => 3.49
),

 [6] => Array
(
 [DATE] => 01.03.17
 [STATE] => high
 [SUM] => 560355
 [PROCENT] => .66
),

 [7] => Array
(
 [DATE] => 01.03.17
 [STATE] => medium
 [SUM] => 81549849
 [PROCENT] => 95.88
),

 [8] => Array
(
 [DATE] => 01.03.17
 [STATE] => low
 [SUM] => 2942863
 [PROCENT] => 3.46
)

);


to lead to such a mind $newarray:
$newarray = Array
(
 [0] => Array
(
 [DATE] => 01.01.17
 [high] => 575355
 [a high percentage] => .67
 [medium] => 82031289
 [average percentage] => 96.01
 [low] => 2835822
 [the low percentage] => 3.32
)

 [1] => Array
(
 [DATE] => 01.02.17
 [high] => 540355
 [a high percentage] => .64
 [medium] => 81360189
 [average percentage] => 95.87
 [low] => 2964194
 [the low percentage] => 3.49
)

 [2] => Array
(
 [DATE] => 01.03.17
 [high] => 560355
 [a high percentage] => .67
 [medium] => 81549849
 [average percentage] => 96.01
 [low] => 2942863
 [the low percentage] => 3.32
)

)


I tried something like this not solved the problem:
$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'];
}
 }


Please help
June 5th 19 at 21:42
2 answers
June 5th 19 at 21:44
Solution
$newarray = [];
foreach ($oldarray as $item) {
 $newarray[$item['DATE']]['DATE'] = $item['DATE'];
 $newarray[$item['DATE']][$item['STATE']] = $item['SUM'];
 $newarray[$item['DATE']][$item['STATE'] . 'percentage'] = $item['PROCENT'];
}


however, in this case, you are in the new array keys will be the date ('01.02.17', '01.02.17', ...)

PS key of the form 0,1,2,3, you can use this bike if so much is necessary
$newarray = array_combine(array_keys(array_fill($i = 0, count($newarray), $i++)), $newarray);

upd: it's better
$newarray = array_values($newarray);
We can so be easier?

$newarray = array_values($newarray); - harmon_Carter86 commented on June 5th 19 at 21:47
exactly!
something I actually bike a terrible namutili
forgot odd about the array_values and that of his get
thank you) - nikolas.Reichert commented on June 5th 19 at 21:50
June 5th 19 at 21:46
bring a date to integer and use as the array key

Find more questions by tags ArraysPHP