Php several different array to calculate a different size and add up?

assume that the front end is

<input type="hidden" name="cart_prod_id[]" value="<?=$row["prod_id"];?>">
<input type="hidden" name="cart_quantity[]" value="<?=$row["quan"];?>">

backend

foreach($_POST["cart_prod_id"] as $value){
   echo $value;
}
foreach($_POST["cart_quantity"] as $value){
   echo $value;
}

you can get a hypothetical value after sending it

11510612910751031

but it is

// ID
115
106
129
107

// 
5
10
3
1

I will first find out the merchandise ID, to find his own price
and then come back multiplied by the corresponding quantity

// ID -> 
115 -> 5
106 -> 10
129 -> 3
107 -> 1

how can I calculate the price of each item and add it up?
what I do is like this
, but it only counts the last one

.
$i = 0;
$productTotal = null;
foreach($_POST["cart_prod_id"] as $value){
      $product = mysqli_fetch_array($pdo->query(
        "SELECT
          p.price,
          p.original_price
        FROM `product` as p
        WHERE p.prod_id = "{$value}" "
      ));

      $productTotal += $product["price"] * $_POST["cart_quantity"][$i];

      $iPP;
    }
    
echo $productTotal;

the train of thought is dead, please drop it

Oct.03,2021


<?php
-sharp 
$goods_id = [1,2,3,4,5,6];
$number = [1,5,6,7,7,8];

$goods_number = array_combine($goods_id,$number);
$goods_id_tmp = implode(',', $goods_id);
$sql = <<<SQL
SELECT 
    `p`.`prod_id`,`p`.`price`,`p`.`original_price`
FROM `product` as p
WHERE `p`.`prod_id` in ({$goods_id_tmp})

SQL;
-sharp .... SQL  
$result = [
    [
    'prod_id'=>2,'price'=>'10.22','original_price'=>'100.00',
    ],
    [
    'prod_id'=>2,'price'=>'120.22','original_price'=>'10310.00',
    ],
    [
    'prod_id'=>3,'price'=>'130.22','original_price'=>'103210.00',
    ],
    [
    'prod_id'=>4,'price'=>'150.22','original_price'=>'12300.00',
    ],
];
$result = array_reduce($result, function($item,$next)use($goods_number){
    $number =$goods_number[$next['prod_id']]??0; 
    return bcmul($next['price'],$number,2);
},0);

var_dump($result);
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e7ea6f-9f1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e7ea6f-9f1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?