php - Create an array from other 2 -


i have following array:

array ( [aflashparties] => array     (         [2015-07-07] => 20         [2015-07-08] => 48         [2015-07-09] => 42         [2015-07-10] => 94         [2015-07-11] => 0         [2015-07-12] => 0         [2015-07-13] => 6         [2015-07-14] => 0     ), [arapidesparties] => array     (         [2015-07-07] => 62         [2015-07-08] => 6         [2015-07-09] => 3         [2015-07-10] => 17         [2015-07-11] => 0         [2015-07-12] => 0         [2015-07-13] => 241         [2015-07-14] => 0     ) ) 

i'd turn array this:

array ( [0] => array     (         [date]   => 2015-07-07         [flash]  => 20         [rapide] => 62         [total]  => 82     ), [1] => array     (         [date]   => 2015-07-08         [flash]  => 48         [rapide] => 6         [total]  => 54     ),     ..... ) 

so idea create array has date, flash (number [aflashparties]), rapid - umber [arapidesparties]) , total (sum of flash , rapid). can me please?

you have parse arrays

$ret = []; $keys = array_keys($a['aflashparties']); foreach ($keys $key) {     $ret[] = [         'date' => $key,         'flash' => $a['aflashparties'][$key],         'rapide' => $a['arapidesparties'][$key],         'total' => $a['aflashparties'][$key] + $a['arapidesparties'][$key]     ]; } 

you may have check existence of keys if there not dates in arrays.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -