sum of values of an element of a repeating group

enrb

Member
I'm trying to do the sum of values of an element of a repeating group,
I first want to multiply two values of two elements of a repeating group and then add the result, to do this I wrote this code in a calc element:


$products = array_map(function($a, $b) {

if (strpos($b, '1') !== false) {
$b = 1;
} else {
$b = 0;
}

return $a * $b;
}, $data['mylist___numberqty_raw'], $data['mylist___flagyes_raw']);


$sum = array_sum($products);

return $sum;



I activated the ajax calculation, but when I insert a number in the mylist___numberqty_raw element, the calculation continues to run and returns nothing.

Am I doing something wrong in my code?
 
Nothing, sorry, I solved it...
Here is the correct code I use:

$products = array_map(function($a, $b) {

if (strpos($b, '1') !== false) {
$b = 1;
} else {
$b = 0;
}

return $a * $b;
}, $data['mylist___numberqty_raw'], $data['mylist___flagyes']);


$sum = array_sum($products);

return $sum;
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top