如何比较POST响应数组值? [英] How to compare POST response to array values?
本文介绍了如何比较POST响应数组值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有困难,从用户输入比较$ _ POST一组数组值的。
我已经设置了以下变量...
$响应= $ _ POST ['答案'];
...和选定的范围内可能的正确答案,并将它们存储在一个阵列...
$ =解决方案阵列('ANSWER1','ANSWER2','ANSWER3');
我已经试过检查/像这样比较...
如果(价值($响应)!==(解决方案)
{$错误['结果'] =错误答案。;}
我知道这是行如果(价值($响应)!==(
解决方案
)。
解决方案
in_array()
是您的朋友:
$ =正确in_array($响应,解决方案);
I'm having difficulty comparing the $_POST from a user input to a set of array values.
I've set the following variable ...
$response = $_POST['answer'];
... and selected a range of possible correct answers and stored them in an array ...
$solutions = array('answer1','answer2','answer3');
I've tried checking/comparing like this ...
if (value($response) !== ($solutions)
{$error['result'] = "Wrong answer.";}
I know it's the line if (value($response) !== ($solutions)
.
解决方案
in_array()
is your friend:
$correct = in_array($response, $solutions);
这篇关于如何比较POST响应数组值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文