如何使用 php 在同一个数组中将数量和价格相乘?

How do you multiply quantity and price within the same array using php?

这是我的多维数组

<?php
    $total = array (

                      array(
                        "prod_price" => 15,
                        "quantity" => 3
                      ),

                      array(
                        "prod_price" => 8,
                        "quantity" => 2
                      )
?>

我正在尝试以 table

的形式显示所有这些
<table>
     <tr>
       <th>Price</th>
       <th>Quantity</th>
       <th>Sub Total</th>
     </tr>
     <?php
     foreach($total as $p){
       ?>
     <tr>
       <td><?php echo $p["prod_price"];?></td>
       <td><?php echo $p["quantity"]; ?></td>

     </tr>
    <?php
   }
   ?>
   </table>

但我不知道如何将数量和价格相乘并根据他们的 table 显示出来...... |价格|数量|小计| |:----|:--------|:--------| |15 | 3 | | |8 | 2 | |

Table

如果有人能给我建议,告诉我如何通过仍然使用多维数组来做到这一点,我会很高兴。

你可以简单地这样做

<table>
  <tr>
    <td>Price</td>
    <td>Quantity</td>
    <td>Total</td>
   </tr>
   <?php foreach($total as $data){?>
   <tr>
    <td><?php echo $data['prod_price'];?></td>
    <td><?php echo $data['quantity'];?></td>
    <td><?php echo $data['prod_price'] * $data['quantity'];?></td>
   </tr>    
   <?php }?>
</table>