获取具有2个或更多条件的foreach循环的值

问题描述 投票:-1回答:1

我试图从我的HTML表单插入多个记录到我的数据库使用PHP我只是了解到有可能有2个或更多条件的foreach循环现在我的问题是我如何获得这些值并将其插入我的数据库?这是我的示例代码:

 while($p = mysqli_fetch_assoc($qry)){
   // this loop has more than 1 data to fetch
 ?>
   <input type="hidden" name="studName[]" value="">
   <input type="hidden" name="studId[]" value="">
   <input type="" name="text1[]" value="">
 <?php
 }

现在从这个文本框数组中获取每个值,这是我的代码:

 foreach (array($text1, $studName, $studId) as $data) {
  //qry for inserting value from array in one table
 }
php mysqli
1个回答
0
投票

你可以这样使用变量。 (如果所有数组的大小相同)。

foreach($text1 as $key => $text){
   echo $text1[$key];
   echo $studName[$key];
   echo $studId[$key];
}
© www.soinside.com 2019 - 2024. All rights reserved.