【发布时间】:2018-01-08 08:52:59
【问题描述】:
我想在我的 html 表格的每一行中显示这个数据,我该怎么做?
<?php
$test = $object2->schoolname;
$array = explode(',', $test);
echo $array[0];
//print_r($myArray); --> output: Array( [0] => testSchool2 [1] => test)
?>
我能想到的唯一方法是使用这样的东西:
<td>
<input type="text" name='schoolname[]' value="<?php
$test = $object2->schoolname;
$array = explode(',', $test);
echo $array[0];
?>" class="form-control"/>
</td>
但是我必须对每一行都这样做,我想表明如果我在数组中有 2 个数据,那么该行的 2 个必须包含这些数据,我不想手动放入数组 [0 ] 像这样。我怎样才能做到这一点?谁能帮我?非常感谢。
我的 html 表是基于这个的: https://bootsnipp.com/snippets/featured/dynamic-table-row-creation-and-deletion
【问题讨论】:
-
阅读更多关于循环的信息。 php.net/manual/en/control-structures.foreach.php
-
@hassan 我已经读过它,我尝试关注这里,stackoverflow.com/questions/9711175/…,但仍然无法做到,因为它是一个动态表
-
您链接的问题的答案清楚地表明相同:使用循环。
-
@commonsense 是的,它是相似的,只是我使用的是动态表,我想显示里面的值可能吗?
-
“动态表”是什么意思?是什么让您的餐桌充满活力?编辑您的问题并显示表格代码。