我有一个多维数组,我该如何使用它?我想在for
循环中使用每个单独的数组。PHP通过多维数组循环遍历
我想要的是能够将每个部分放入我的数据库中,例如 条目中的db no。 0 - > 1和4 条目在db no。 1 - > 5和6 条目在db no。 2 - > 1和4以及5和6
我有这样的代码:
<?php
print_r($calculatie_id);
for ($i=0; $i<=3; $i++)
{
?>
<tr>
<td>
<?php
foreach ($calculatie_id[$i] as $value)
{
echo $value;
}
?>
print_r($calculatie_id); gives
Array ([0] => Array ([0] => 4 [1] => 6) [1] => Array ([0] => 1 [1] => 5) [2] => Array ([0] => 5 [1] => 6) [3] =>)
但是用foreach
当我只得到46
一些额外的信息:
这个阵列是由for循环中的多重选择创建。欢迎任何其他建议。
for ($i=0; $i<=$aantal_regels_corr; $i++)
{
?>
<tr>
<td>
<?php
// maak select name
$calculatie_id = 'calculatie_id'.$i;
// rest van formulier
if($error_vergeten[$i] == "ja"){ $error_omschr = $error_omschr_vergeten[$i]; include('includes/input_error.php'); } ?> <textarea rows="7" cols="80" name="omschrijving[]" /><?php echo $omschrijving[$i]; ?></textarea>
</td>
<td colspan="2">
<select multiple="multiple" width="50" size="7" name="<?php echo $calculatie_id ?>[]" style="width: 150px">
<?php
$sql_calc = "select id, naam, actief from sp_calculatie WHERE (offerte_id = '".$row['off_offerte']."' OR offerte_id = '".$offerte_id."') AND actief = 'ja' ORDER BY id ASC";
$res_calc = mysql_query($sql_calc,$con);
while ($row_calc = mysql_fetch_assoc($res_calc)){
?>
<option value="<?php echo $row_calc["id"] ?>"><?php if (empty($row_calc["naam"])) { echo $row_calc["id"]; } else { echo $row_calc["naam"]; } ?></option>
<?php } ?></select>
</td>
</tr>
<?php } ?>
看看更新! – 2010-05-06 20:54:59