如何在phpp中排列数组数据,以便它可以匹配2个或更多值?
EX: users.php
$USERS["username1"] = "password1";
direct.php
include("users.php");
$user = $_POST['user'];
$pass = $_POST['pass'];
if ($USERS[$user]==$pass) {
echo "welcome";
}
所以在$ USERS数组中,如果用户输入
,该值将满足if语句“username1”和“passsword1”
我想要做的是允许“username1”与其他值
配对 $USERS["username1"] = "password1" , "password3" , "password109";
即使用户输入了这3个中的任何一个
"password1" , "password3" , "password109"
无论如何都会满足if语句吗?
答案 0 :(得分:4)
我猜你需要的是in_array()
$users['username1'] = array('password1','password3','azeadnfksfn');
if (in_array($password,$users[$user])) {
echo 'Welcome';
}
答案 1 :(得分:1)
您可以使用in_array。带密码的$USERS["username1"]
应该是一个数组,然后你可以这样做:
include("users.php");
$USERS["username1"] = array("password1" , "password3" , "password109");
$user = $_POST['user'];
$pass = $_POST['pass'];
if (in_array($pass,$USERS["username1"])) {
echo "welcome";
}