[ create a new paste ] login | about

Link: http://codepad.org/puCAcFBB    [ raw code | output | fork ]

PHP, pasted on Nov 6:
<?php
$container = array(
  array(
    "ticket_labor_ot_travel_c" => "34.50",
    "ticket_labor_travel_c" => "23.00",
    "ticket_labor_ot_c" => "34.50",
    "ticket_labor_reg_c" => "23.00",
    "ticket_labor_user_id" => "319",
    "ticket_labor_tot_hours" => "0.50",
    "ticket_labor_reg_hours" => "0.50",
    "ticket_labor_ot_hours" => "0.00",
    "ticket_labor_travel_hours" => "0.00",
    "ticket_labor_ot_travel_hours" => "0.00",
  ),
  array(
    "ticket_labor_ot_travel_c" => "0.00",
    "ticket_labor_travel_c" => "5.00",
    "ticket_labor_ot_c" => "0.00",
    "ticket_labor_reg_c" => "0.00",
    "ticket_labor_user_id" => "0",
    "ticket_labor_tot_hours" => "0.00",
    "ticket_labor_reg_hours" => "0.00",
    "ticket_labor_ot_hours" => "0.00",
    "ticket_labor_travel_hours" => "0.00",
    "ticket_labor_ot_travel_hours" => "10.00",
  )
);

$result = array();
foreach ($container as $innerArray) {
    foreach ($innerArray as $key=>$value) {
        $result[$key] = number_format($result[$key] + $value, 2);
    }
}
var_dump($result);


Output:
array(10) {
  ["ticket_labor_ot_travel_c"]=>
  string(5) "34.50"
  ["ticket_labor_travel_c"]=>
  string(5) "28.00"
  ["ticket_labor_ot_c"]=>
  string(5) "34.50"
  ["ticket_labor_reg_c"]=>
  string(5) "23.00"
  ["ticket_labor_user_id"]=>
  string(6) "319.00"
  ["ticket_labor_tot_hours"]=>
  string(4) "0.50"
  ["ticket_labor_reg_hours"]=>
  string(4) "0.50"
  ["ticket_labor_ot_hours"]=>
  string(4) "0.00"
  ["ticket_labor_travel_hours"]=>
  string(4) "0.00"
  ["ticket_labor_ot_travel_hours"]=>
  string(5) "10.00"
}


Create a new paste based on this one


Comments: