如何确保我的表单在PHP中以数组形式出现

时间:2016-01-20 16:25:57

标签: php multidimensional-array array-push

这个想法是当你点击Volgende时,将$ getal1,$ getal1,$ soort和$ antwoord放入一个数组中。如果这是第二次,那就是第一次和第二次。

这是我的英文PHP代码

<?php   
$kind = $_SESSION['kind'];//get the kind of  task choose from +-/*
$class = $_SESSION['class'];//get the number of class
$answers = $_SESSION['answers'];//get the previous answers
if($class == "klas4"){
    $max = 10;
}
if($class == "klas5"){
    $max = 20;
}
if($class == "klas6"){
    $max = 100;
}
$number1 = mt_rand(0,  $max);
$number2 = mt_rand(0,  $max);
?>
<div class="som">
    <form action="" method="post">
        <?php echo $number1 . $kind . $number2 ?>
        <input name="answer" type="number">
        <input type="submit" name="next" value="next"> 
    </form>
</div>
<?php    
    if(isset($_POST['next']))
    {   
    $answer = $_POST['next'];
    $answers=array($answers);
    array_push($answers,$number1,$kind, $number2,$answer);

    var_dump($answers);
    $_SESSION['answers']=$answers;
    }
?>

如果执行此代码,一切都会结合在一起。

我希望有人可以提供帮助

1 个答案:

答案 0 :(得分:0)

尝试用英语制作你的代码btw,我是荷兰语,所以我可以阅读它,但用你自己的语言做它是不好的做法。

它不起作用的原因是因为没有定义$ antwoorden。 你不做任何计算。 你节省了$ antwoorden,但再也没有把它从会议中删除。

你可以发布整个脚本吗? 我想你使用1个php文件。

我还认为你应该更清楚脚本应该做什么。