我在创建动态表单时遇到问题,这是我的数组
$myThemeConfig = array (
'slid_img' =>
array (
'img_1' => 'im1.jpg',
'img_2' => 'im2.jpg',
'img_3' => 'im3.jpg',
'img_4' => 'im4.jpg',
'img_5' => 'im5.jpg',
'img_6' => 'im6.jpg',
'img_7' => NULL,
'img_8' => NULL,
'img_9' => NULL,
'img_10' => NULL,
),
'slid_til' =>
array (
'title_1' => 'title1 is your title 1',
'title_2' => 'title2 is your title 2',,
'title_3' => 'title3 is your title 3',
'title_4' => 'title4 is your title 4',
'title_5' => 'title5 is your title 5',
'title_6' => 'title6 is your title 6',
'title_7' => NULL,
'title_8' => NULL,
'title_9' => NULL,
'title_10' => NULL,
);
我希望在html上显示
<tbody id="copyf">
<tr>
<td>Slider Image 1</td>
<td><div><input type="text" value="im1.jpg" name="img_1"></div></td></tr>
<tr>
<td>Slider Title 1></td><td><div><textarea name="title_1">title1 is your title 1</textarea></div></td></tr></tbody>
<tbody id="copyf">
<tr>
<td>Slider Image 2</td>
<td><div><input type="text" value="im2.jpg" name="img_2"></div></td></tr>
<tr>
<td>Slider Title 2 ></td><td><div><textarea name="title_2">title2 is your title 2</textarea></div></td></tr></tbody>
<tbody id="copyf">
<tr>
<td>Slider Image 3</td>
<td><div><input type="text" value="im3.jpg" name="img_3"></div></td></tr>
<tr>
<td>Slider Title 3 ></td><td><div><textarea name="title_3">title3 is your title 3</textarea></div></td></tr></tbody>
依旧......
我尝试使用foreach循环,但它只循环一个数组,
这里是我工作的代码。
它几乎让我绝望,因为我不是专家ini php代码..
请p ..请... ..)答案 0 :(得分:0)
<?php
$c = count ($myThemeConfig ['slid_img']);
for ($i=1; $i<=$c; $i++) : ?>
<tbody id="copyf">
<tr>
<td>
Slider Image <?php echo $i; ?>
</td>
<td>
<div>
<input type="text" value="<?php echo $myThemeConfig['slid_img'] ['img_' . $i]; ?>" name="img_<?php echo $i; ?>" />
</div>
</td>
</tr>
<tr>
<td>
Slider Title <?php echo $i; ?> >
</td>
<td>
<div>
<textarea name="title_<?php echo $i; ?>"><?php echo $myThemeConfig['slid_til'] ['title_' . $i]; ?></textarea>
</div>
</td>
</tr>
</tbody>
<?php endfor; ?>