我正在测试一个简单的兑换系统,但它不起作用。当用户输入有效代码时,它不会将其添加到“已使用”数组中。
这是完整的代码:
<?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); 但这也不起作用。