【发布时间】:2018-09-01 08:04:53
【问题描述】:
我有一个这样的数组:-
$str = array(
array(
'amount' => 1.87,
'user' => 'hello',
),
array(
'amount' => 0.9,
'user' => 'test',
),
array(
'amount' => 9,
'user' => 'hello',
),
array(
'amount' => 1.4,
'user' => 'test',
)
);
现在我在 HTML 表格中为用户“测试”显示这些数据:-
<thead>
<tr>
<th>Amount</th>
<th>User</th>
</thead>
<tbody>
<tr>
<td><?php
foreach ($str as $new_str) {
if ($new_str['user'] == "test") {
echo $new_str['amount'];
echo "<br />";
}
}
?></td><td><?php
foreach ($str as $new_str) {
if ($new_str['user'] == "test") {
echo $new_str['user'];
echo "<br />";
}
}
?></td>
</tr>
</tbody>
但现在的问题是,当我使用此代码时,它会显示数量和用户作为一个整体,而不是两个不同的行。我怎样才能解决这个问题?有什么帮助吗?
【问题讨论】: