PHP两个Foreach循环在每次迭代中将每个循环的值相乘


PHP Two Foreach Loops Multiply values from each loop on each iteration

我有这两个循环

          foreach($decode_pricing->items as $items=>$item) {
              $cost .= number_format($item->pricing[0]->cost, 2);
          }
          foreach($qty_ea as $ea) {
              $ff .= $ea;
          }

顶部foreach输出

44.8244.8244.82

格式化

44.82
44.82
44.82

底部foreach输出

121

格式化

1
2
1

如何在循环的每次迭代中将顶部值与底部值相乘?

我想要的输出是

44.82
89.64
44.82

您可以执行类似的操作

 foreach($decode_pricing->items as $key => $item) {
          $cost .= $qty_ea[$key] * number_format($item->pricing[0]->cost, 2);
      }

假设您的两个数组都是Numeric。