Php 使用foreach显示数组中的数据

Php 使用foreach显示数组中的数据,php,arrays,foreach,codeigniter-3,Php,Arrays,Foreach,Codeigniter 3,表中有3列,其中所有列值都存储在数组中。 这是我的桌子 id bill_id description quantity amount 16 16 ["item1","item2","item3"] ["2","1","2"] ["100","100","150"] 这是我查看结果的代码 <?php $description=json_decode($result-

表中有3列,其中所有列值都存储在数组中。 这是我的桌子

id   bill_id         description               quantity             amount

16    16           ["item1","item2","item3"]     ["2","1","2"]      ["100","100","150"]
这是我查看结果的代码

    <?php $description=json_decode($result->description)?>
    <?php $amount=json_decode($result->amount)?>
    <?php $quantity=json_decode($result->quantity);?>
       <?php foreach($description as $row){?>
       <tr class="item-row">


       <td class="description"><textarea class="textarea" name="description[]"><?php echo $row;?></textarea></td>
       <td><textarea name="amount[]" class="cost textarea"><?php echo $amount;?></textarea></td>
       <td><textarea name="quantity[]" class="qty textarea"><?php echo $quantity;?></textarea></td>

      <td><span class="price"></span></td>
  </tr>
  <?php }?>

如果我给foreach指定amount和quantity,结果会重复出现

如果所有3个数组的索引都相同,那么您可以通过一个foreach/for循环中的索引直接访问它,比如
$amount[$index]
和$quantity[$index]`。但是我们可以在一个foreach循环中给出3个值吗是的,您可以执行
foreach($description as$index=>$row){echo$row;echo$amount[$index];echo$quantity[$index];}
用于所有3个值,但您需要记住,所有3个数组都必须索引相同。非常感谢我现在理解了……如果所有3个数组的索引相同,那么您可以通过一个foreach/for循环直接访问它,就像
$amount[$index]
和$quantity[$index]`。但是我们能在一个foreach循环中给出3个值吗?是的,你可以对所有3个值执行
foreach($index=>$row){echo$row;echo$amount[$index];echo$quantity[$index];}
操作,但你需要记住,所有3个数组的索引必须相同。非常感谢,现在我明白了。。。
            description        amount           quantity
             item1               2               100
             item2               1               100
             item3               2               150