这里我有一个多维数组;在此数组中,我有两个索引:
现在,我要执行的操作意味着我必须从这两个index
中获取值,并且必须在html表中显示,但是我不知道如何在html表中显示数组值。我是开发新手,请给我更新答案。
print_r($ viewWorkSheet);
Array
(
[mandatoryCheckingReport] => Array
(
[uniformID] => Array
(
[testCase] => uniformID empty checking
[devTeamResult] => success
[testingTeamResult] => test case success
)
[studentID] => Array
(
[testCase] => studentID empty checking
[resultCode] => C001
[devTeamResult] => success
[testingTeamResult] => test case success
)
)
[specialCharectorReport] => Array
(
[uniformID] => Array
(
[testCase] => uniformID specialCharector checking
[devTeamResult] => success
[testingTeamResult] => test case failure
)
[studentID] => Array
(
[testCase] => studentID specialCharector checking
[devTeamResult] => success
[testingTeamResult] => test case failure
)
)
)
我的预期输出是这样的:
<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<h2>HTML Table</h2>
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>Heading</th>
<th>Test Case</th>
<th>Input Field</th>
<th>DevTeam Result</th>
<th>TestingTeam Result</th>
<th>Expected Result</th>
</tr>
</thead>
<tbody>
<!-- mandatoryCheckingReport array values start here -->
<tr>
<td rowspan="5">mandatoryCheckingReport</td>
<td>uniformID empty checking</td>
<td>uniformID</td>
<td>success</td>
<td><small class="label label-success"> test case success</small></td>
<td>OK</td><!-- Static is Ok fine -->
</tr>
<tr>
<td>studentID empty checking</td>
<td>studentID</td>
<td>success</td>
<td><small class="label label-success"> test case success</small></td>
<td>OK</td><!-- Static is Ok fine -->
</tr>
<tr>
<td>startFrom empty checking</td>
<td>startFrom</td>
<td>success</td>
<td><small class="label label-success"> test case success</small></td>
<td>OK</td><!-- Static is Ok fine -->
</tr>
<tr>
<td>limit empty checking</td>
<td>limit</td>
<td>success</td>
<td><small class="label label-success"> test case success</small></td>
<td>OK</td><!-- Static is Ok fine -->
</tr>
<tr>
<td>profileID empty checking</td>
<td>profileID</td>
<td>success</td>
<td><small class="label label-success"> test case failure</small></td>
<td>OK</td><!-- Static is Ok fine -->
</tr>
<!-- specialCharectorReport array values start here -->
<tr>
<td rowspan="5">specialCharectorReport</td>
<td>uniformID specialCharector checking</td>
<td>uniformID</td>
<td>success</td>
<td><small class="label label-success"> test case failure</small></td>
<td>OK</td><!-- Static is Ok fine -->
</tr>
<tr>
<td>studentID specialCharector checking</td>
<td>studentID</td>
<td>success</td>
<td><small class="label label-success"> test case failure</small></td>
<td>OK</td><!-- Static is Ok fine -->
</tr>
<tr>
<td>startFrom specialCharector checking</td>
<td>startFrom</td>
<td>success</td>
<td><small class="label label-success"> test case success</small></td>
<td>OK</td><!-- Static is Ok fine -->
</tr>
<tr>
<td>limit specialCharector checking</td>
<td>limit</td>
<td>success</td>
<td><small class="label label-success"> test case success</small></td>
<td>OK</td><!-- Static is Ok fine -->
</tr>
<tr>
<td>profileID specialCharector checking</td>
<td>profileID</td>
<td>success</td>
<td><small class="label label-success"> test case failure</small></td>
<td>OK</td><!-- Static is Ok fine -->
</tr>
</tbody>
</table>
</body>
</html>
答案 0 :(得分:0)
您的代码实际上可以,但是有一个小错误。在您的代码中,每行都打印出$key
。我已修复此代码,以使$key
仅在$value
显示开始时显示,因为$key
与rowspan
一起显示。
编辑
我更改rowspan
的值以使其更动态。
<tbody>
<?php foreach( $viewWorkSheet as $key => $value): ?>
<?php $row = true; ?>
<?php foreach( $value as $key1 => $value1): ?>
<tr>
<?php if ($row): ?>
<td rowspan="<?php echo count($value); ?>"><?php echo $key; ?></td>
<?php $row = false; ?>
<?php endif; ?>
<td><?php echo $value1['testCase']; ?></td>
<td><?php echo $key1; ?></td>
<td><?php echo $value1['devTeamResult']; ?></td>
<td><small class="label label-success"> <?php echo $value1['testingTeamResult']; ?></small></td>
<td>OK</td><!-- Static is Ok fine -->
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>