我想从表单中获取输入并将其保存到php数组并打印该数组。有两个文件即array.php和marks.php.I认为我在搞静态。请帮帮我!获取此代码的输出
marks.php
<style type="text/css">
.my_table{
margin-top:150px;
margin-left:400px;
}
</style>
<?php
if(!isset($_POST['send'])){
?>
<table align='center' class='my_table'>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<tr><th></th><th align='left'>Student Marks</th></tr>
<tr><td>enter subject</td><td><input type='text' name='subject'></td></tr>
<tr><td>enter marks</td><td><input type='text' name='marks'></td></tr>
<tr><td colspan='2' align='right'><input type='submit' value='submit' name='send'/> </td></tr>
</form>
</table>
<?php
}
else{
include 'array.php';
$svtoarray=new SaveMarks();
$svtoarray->addToArray($_POST['marks']);
$svtoarray->printArray();
}
?>
array.php
<?php
class SaveMarks{
static $index=0;
function SaveMarks(){
}
static $marks=array();
function addToArray($value){
$marks[$index]=$value;
$index++;
}
function printArray(){
$countarr=count($marks);
for($ind=0;$ind<$countarr;$ind++){
print $marks[ind];
}
}
}
?>
$ _POST本身就是一个数组。为什么所有复杂的东西? –
我觉得'
'比'好'