0

我正在测试一个简单的兑换系统,但它不起作用。当用户输入有效代码时,它不会将其添加到“已使用”数组中。

这是完整的代码:

<?php

$submit = $_POST['submit'];
$code   = $_POST['code'];

$used = array(
    "swig",
    "sworgle"
);

$valid = array(
    "swug",
    "sweggle"
);

if($submit){

if(in_array($code, $valid)){
    if(!in_array($code, $used)){
    echo "Congratulations! That is a correct code. <a href='index.php'>Click here to go back</a>";
    $used[] = $code;
} elseif(in_array($code, $used))
    echo "This code has already been used. <a href='index.php'>Click here to go back</a>";
} elseif(!in_array($code, $valid))
    echo "This code is invalid <a href='index.php'>Click here to go back</a>.";

}
else
    echo "Nice try. <a href='index.php'>Go back</a>.";

?>

我试过 array_push($used, $code); 但这也不起作用。

4

1 回答 1

0

我认为可能是您正在遍历数组中的参数的代码,我建议您将变量设置为 print $code

于 2013-11-07T17:08:25.537 回答