ricbax Posted October 12, 2008 Share Posted October 12, 2008 I am working with the follow 2 arrays based of some manipulation from a XML document. //statuses an item has been in. Array ( [0] => New [1] => Work in Progress [2] => Waiting customer reply [3] => Updated [4] => Work in Progress [5] => Updated [6] => Work in Progress [7] => Waiting customer reply [8] => Closed ) // time in hours Array ( [0] => 0.08 [1] => 138.75 [2] => 25.5 [3] => 45.72 [4] => 8.13 [5] => 0.27 [6] => 2.01 [7] => 19.12 [8] => 215.38 ) How can I get the total amount of hours based on statuses. This is an example, statues will vary per item. New = 0.08, Work in Progress = 148.89 (total of keys 1,4,6), etc. Link to comment https://forums.phpfreaks.com/topic/128090-solved-associating-values-from-2-different-arrays-and-getting-a-total-amount/ Share on other sites More sharing options...
wildteen88 Posted October 12, 2008 Share Posted October 12, 2008 Something like <?php $status = array('New', 'Work in Progress', 'Waiting customer reply', 'Updated', 'Work in Progress', 'Updated', 'Work in Progress', 'Waiting customer reply', 'Closed'); $time = array(0.08, 138.75, 25.5, 45.72, 8.13, 0.27, 2.01, 19.12, 215.38); foreach($status as $key => $value) { if(isset($total[$value])) $total[$value] += $time[$key]; else $total[$value] = $time[$key]; } echo '<pre>' . print_r($total, true) . '</pre>'; ?> Link to comment https://forums.phpfreaks.com/topic/128090-solved-associating-values-from-2-different-arrays-and-getting-a-total-amount/#findComment-663333 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.