0

我在创建动态表单时遇到问题,这是我的数组

$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 循环,但它只循环一个数组,

这是我工作的代码。

http://pastebin.com/w5jz0pGg

它几乎让我绝望,因为我不是专家 ini php 代码..

拜托..拜托拜托.. :)

4

1 回答 1

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; ?>
于 2012-05-30T18:08:36.797 回答