php - organize the order of element and push the total of sub-array -


 $base_arr =   array   (       1 => array           (           0 => 1,           1 => 2,           2 => 5,           3 => 5           ),       3 => array           (           0 => 1,           1 => 2           ),       7 => array           (           0 => 1,           1 => 4           )    ); 

i want re organize order of element , push total of sub-array main array.the result want return this:

 $new_arr =   array(      0 => 1,      1 => 2,      2 => 5,      3 => 5,      4 =>13, //this total 1+2+5+5 = 13      5 => 1,      6 => 2,      7 => 3,//this total 1+2 = 3      8 => 1,      9 => 4,      10 =>5 //this total 1+4 = 5     ); 

who can me please ,thanks.

good chance try closures in php 5.3:

   $new = array();     array_walk($base_arr, function ($item) use (&$new) {                $new = array_merge($new, $item);                $new []= array_sum($item);             }     );      var_dump($new); 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -