Jump to content

[SOLVED] Associating values from 2 different arrays and getting a total amount.


ricbax

Recommended Posts

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.

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>';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.