PHP custom regroup array -
i want regroup array have problem on columns , grouping child arrays :
my array :
[0] => array ( [0] => 1393/03 [1] => 5666562 [2] => 5 ) [1] => array ( [0] => 1393/03 [1] => 491380 [2] => 6 ) [2] => array ( [0] => 1393/03 [1] => 4210423 [2] => 30 ) [3] => array ( [0] => 1393/03 [1] => 351000 [2] => 55 ) [4] => array ( [0] => 1393/03 [1] => 53000 [2] => 60 ) [5] => array ( [0] => 1393/02 [1] => 15799573 [2] => 5 ) [6] => array ( [0] => 1393/02 [1] => 1144313 [2] => 6 ) [7] => array ( [0] => 1393/02 [1] => 12131004 [2] => 30 ) [8] => array ( [0] => 1393/02 [1] => 39000 [2] => 55 )
result: (must :)
[0] => array ( [date] => 1393/03 [5] => 5666562 [6] => 491380 [30] => 4210423 [60] => 53000 ) [1] => array ( [date] => 1393/02 [5] => 15799573 [6] => 1144313 [30] => 12131004 [60] => 39000 )
i try self foreach arrays
, references samples around internet , stack-overflow , don't find solution.
simple foreach loop should suffice. consider example:
$new_values = array(); $values = array( array('1393/03', 5666562, 5), array('1393/03', 491380, 6), array('1393/03', 4210423, 30), array('1393/03', 351000, 55), array('1393/03', 53000, 60), array('1393/02', 15799573, 5), array('1393/02', 1144313, 6), array('1393/02', 12131004, 30), array('1393/02', 39000, 55),); foreach($values $key => $value) { $new_values[$value[0]]['date'] = $value[0]; $new_values[$value[0]][$value[2]] = $value[1]; } $new_values = array_values($new_values); echo "<pre>"; print_r($new_values); echo "</pre>";
Comments
Post a Comment