//做表单的时候,会碰到单条字段数据,比如学校的成绩单,排名、分数、名字等等等,运行后开始出现的错误是因为表单没有提交没有数据,直接填写提交就行
<html>
<head>
<style>
table,table td,table th{ //table表格细边框
border:1px solid #000000;
border-collapse:collapse;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form method="post">
<table>
<tr>
<td>排名</td>
<td>名字 </td>
</tr>
<tr>
<td><input style="border: 0px;" name="zs[1][no]" type="text" /></td>
<td><input style="border: 0px;" name="zs[1][name]" type="text" /></td>
</tr>
<tr>
<td><input style="border: 0px;" name="zs[2][no]" type="text" /></td>
<td><input style="border: 0px;" name="zs[2][name]" type="text" /></td>
</tr>
</table>
<input type="submit" />
</form>
<?php
$zs=$_POST['zs'];
$zsstr = json_encode($zs);
$zs2 = json_decode($zsstr,true);//解码
$x = $zs2;
?>
<table>
<tr>
<td>排名</td>
<td>名字</td>
</tr>
<?php foreach ($x as $index => $y) {?>//遍历
<tr>
<td><?php echo $y['no'] ?></td>
<td><?php echo $y['name'] ?></td>
</tr>
<?php } ?>
</table>
</body>
</html>
运行效果图