Sum array values depending dates non-singularity


How about this?

$result = $costs;
foreach ($dates as $i => $d) {
    if ($i > 0 && $dates[$i - 1] == $dates[$i]) {
        $result[$i] += $result[$i - 1];
        $result[$i - 1] = 0;
    }
}
print_r($result);

We're starting with our $costs array, and looping through all the dates... every time we detect that the date is the same as the previous entry, we zero out the previous entry and add it's value to our current location.

Alternate Solution

This isn't exactly what you asked for, but I suspect a more useful solution might be this:

$result = array();
foreach ($dates as $i => $d) {
    $result[$d] = (isset($result[$d]) ? $result[$d] : 0) + $costs[$i];
}
print_r($result);

This will produce a result of:

array(
    '2001-01-01' => 5,
    '2001-02-01' => 34,
    '2001-03-01' => 30,
    '2001-04-01' => 16,
    '2001-05-01' => 0
)

If you're iterating over skillslist, each value passed to your callback will be the individual values of skillslist. So if you want to change the values of skillslist, you can do so by changing the first argument passed to your callback. Like this:

skillslist.forEach(function(skill) {
  var isInSkills = skills.some(function(skillValue) {
    return skillValue.Skill_Values__c === skill.Skill_Values__c;
  });
  if(isInSkills) {
    skill.checked = "Added";
  } else {
    skill.checked = "no";
  }
});

Just change inside your htmldata:

ServiceCharge

to:

orderjson.display[orderOfDisplay[i]]

EDIT Then all the vars ServiceCharge, ServiceTax, VAT, OTHERS, DISCOUNT are not needed any more.

words = ['Yes', 'it is', 'done']
prime_arr = [2, 3, 5, 7, 11, 13]
target = [3, 5, 7]

words.take((prime_arr & target).size).join(" ")

Edited:

prime_arr = [2, 3, 5, 7, 11, 13]
mapping = {
  [3] => 'Yes',
  [3, 5] => 'Yes it is',
  [3, 5, 7] => 'Yes it is done'
}

mapping[prime_arr & [3, 5, 7]] # => 'Yes it is done'
mapping[prime_arr & [3, 5]] # => 'Yes it is'
mapping[prime_arr & [3]] # => 'Yes'

You get a nil when none of the keys in mapping matches.

I would suggest to have variable that holds page's index, and then you just include this into each checkbox: <?php if(is_array($categoriesArr[$pageIndexVariable]) && $categoriesArr[$pageIndexVariable][$checkboxNameOrIdOrwhatever]) echo "checked" ?>

Comments


Message :
Login to Add Your Comments .
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .