<?php
$items = [
[
'qty' => 1,
'weight' => 1,
],
[
'qty' => 2,
'weight' => 1,
],
[
'qty' => 3,
'weight' => 1,
],
[
'qty' => 1,
'weight' => 5,
],
];
$weights = array_column($items, 'weight');
$result =0;
Foreach(array_unique($weights) as $weight){
$weightitems = preg_grep("/". $weight . "/", $weights);
$result += array_sum(array_column(array_intersect_key($items, $weightitems), "qty")) * $weight;
}
Echo $result;
preferences:
68.17 ms | 402 KiB | 5 Q