<table width="503" height="278" border="1">
<tr align="center" valign="middle">
<td height="34" align="center" valign="middle" id="side"><strong>TEST</strong></td>
<td align="center" valign="middle"><strong>METHOD</strong></td>
<td align="center" valign="middle"><strong>COMPEDIA</strong></td>
<td align="center" valign="middle"><strong>SPECIFICATION</strong></td>
<td align="center" valign="middle"><strong>DETERMINED</strong></td>
<td align="center" valign="middle" id="side"><strong>REMARKS</strong></td>
</tr>
<?php foreach ($tests_requested_display2 as $value2) ?><!--has values to populate the compedia and specification cells of the table-->
<?php foreach ($tests_requested_display as $value) : ?> <!-- creates 3 dynamic rows-->
<tr>
<td height="56" align="center" valign="middle" id="side"><?php echo $value->name ?></td>
<td align="center" valign="middle">Weight</td>
<td align="center" valign="middle"><textarea name="compedia[]" cols="10" ><?php echo @$value2->compedia;?></textarea></td>
<td align="center" valign="middle"><textarea name="specification[]" cols="10"><?php echo @$value2->specification;?></textarea></td>
<td align="center" valign="middle">None Deviate</td>
<td align="center" valign="middle" id="side">COMPLIES</td>
</tr>
<?php endforeach; ?>
</table>
第一个 foreach 数组$value
包含 3 个值,这些值创建了一个如上定义但具有 3 行和 6 列的表。我有第二个 foreach 数组 $value2 具有用于填充 compedia 和规范列的数据,如果我 echo $value2->compedia
and $value->specification
,它只返回数组中六个值中的最后一个值,如果我添加与$value
数组相同的 end foreach ,它返回一个奇怪的结果。我错过了什么?
更多信息:
print_r($tests_requested_display)
返回:
Array ( [0] => stdClass Object ( [name] => Dissolution ) [1] => stdClass Object ( [name] => Assay ) [2] => stdClass Object ( [name] => Uniformity of Weight ) ) Array ( [0] => stdClass Object ( [name] => Dissolution ) [1] => stdClass Object ( [name] => Assay ) [2] => stdClass Object ( [name] => Uniformity of Weight ) ) Array ( [0] => stdClass Object ( [name] => Dissolution ) [1] => stdClass Object ( [name] => Assay ) [2] => stdClass Object ( [name] => Uniformity of Weight ) )
并print_r($tests_requested_display2)
返回:
Array ( [0] => stdClass Object ( [name] => Assay [compedia] => Caps [specification] => Tabs ) [1] => stdClass Object ( [name] => Dissolution [compedia] => Tabs [specification] => Caps ) [2] => stdClass Object ( [name] => Uniformity of Weight [compedia] => TabsCaps [specification] => CapsTabs ) ) Array ( [0] => stdClass Object ( [name] => Assay [compedia] => Caps [specification] => Tabs ) [1] => stdClass Object ( [name] => Dissolution [compedia] => Tabs [specification] => Caps ) [2] => stdClass Object ( [name] => Uniformity of Weight [compedia] => TabsCaps [specification] => CapsTabs ) ) Array ( [0] => stdClass Object ( [name] => Assay [compedia] => Caps [specification] => Tabs ) [1] => stdClass Object ( [name] => Dissolution [compedia] => Tabs [specification] => Caps ) [2] => stdClass Object ( [name] => Uniformity of Weight [compedia] => TabsCaps [specification] => CapsTabs ) )
我期望的结果作为一个例子:
<table width="503" height="278" border="1">
<tr align="center" valign="middle">
<td height="34" align="center" valign="middle" id="side"><strong>TEST</strong></td>
<td align="center" valign="middle"><strong>METHOD</strong></td>
<td align="center" valign="middle"><strong>COMPEDIA</strong></td>
<td align="center" valign="middle"><strong>SPECIFICATION</strong></td>
<td align="center" valign="middle"><strong>DETERMINED</strong></td>
<td align="center" valign="middle" id="side"><strong>REMARKS</strong></td>
</tr>
<tr>
<td height="56" align="center" valign="middle" id="side">Assay</td>
<td align="center" valign="middle">Weight</td>
<td align="center" valign="middle"><textarea name="compedia[]" cols="10">Caps</textarea></td>
<td align="center" valign="middle"><textarea name="specification[]" cols="10">Tabs</textarea></td>
<td align="center" valign="middle">None Deviate</td>
<td align="center" valign="middle" id="side">COMPLIES</td>
</tr>
<tr>
<td height="56" align="center" valign="middle" id="side">Dissolution</td>
<td align="center" valign="middle">Weight</td>
<td align="center" valign="middle"><textarea name="compedia[]" cols="10">TabsCaps</textarea></td>
<td align="center" valign="middle"><textarea name="specification[]" cols="10">CapsTabs</textarea></td>
<td align="center" valign="middle">None Deviate</td>
<td align="center" valign="middle" id="side">COMPLIES</td>
</tr>
<tr>
<td height="56" align="center" valign="middle" id="side">Uniformity</td>
<td align="center" valign="middle">Weight</td>
<td align="center" valign="middle"><textarea name="compedia[]" cols="10">Tabs</textarea></td>
<td align="center" valign="middle"><textarea name="specification[]" cols="10">Caps</textarea></td>
<td align="center" valign="middle">None Deviate</td>
<td align="center" valign="middle" id="side">COMPLIES</td>
</tr>
</table>