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.

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.