这是我的数组
Array
(
[0] => Array
(
[0] => 1
[1] => 1
[2] => 1
[3] => 1
[4] => no
)
[1] => Array
(
[0] => 2
[1] => 2
[2] => 2
[3] => 2
[4] => yes
)
[2] => Array
(
[0] => 3
[1] => 3
[2] => 3
[3] => 3
[4] => yes
)
[3] => Array
(
[0] => 4
[1] => 4
[2] => 4
[3] => 4
[4] => no
)
[4] => Array
(
[0] => 5
[1] => 5
[2] => 5
[3] => 5
[4] => yes
)
)
这是我尝试过的,我正在创建一个表 tr 部分,它所做的是为正在显示的每条记录复制自身。这还能怎么写才能正确显示?我知道它一定很简单,我只是无法绕开它。
<?php
$units = json_decode($tablerow);
foreach($units as $unit) : for($i=0;$i<=count($unit)-1;$i++) : ?>
<tr class="rows">
<td><input type='text' name='bedroom[]' value='<?=$unit[$i];?>' class='input-small'></td>
<td><input type='text' name='bath[]' value='<?=$unit[$i];?>' class='input-small'></td>
<td><input type='text' name='sqrt[]' value='<?=$unit[$i];?>' class='input-small'></td>
<td><input type='text' name='price[]' value='<?=$unit[$i];?>' class='input-small'></td>
<td>
<select name='avail[]' class='input-small'>
<option value='yes' <?=($unit[$i] == 'yes') ? 'selected="selected' : '';?>>Yes</option>
<option value='no' <?=($unit[$i] == 'no') ? 'selected="selected' : '';?>>No</option>
</select>
</td>
<td><button type="button" class="btn btn-danger btn-small removeRow">remove</button></td>
</tr>
<?php endfor; endforeach; ?>