如何以简单的方式检查5个变量是否相同或相同?
这是我的示例代码: -
$roster_1 = $_POST['roster_1'];
$roster_2 = $_POST['roster_2'];
$roster_3 = $_POST['roster_3'];
$roster_4 = $_POST['roster_4'];
$roster_5 = $_POST['roster_5'];
$checkcommon = array($roster_1 , $roster_2 , $roster_3 , $roster_4 , $roster_5);
if(array_sum($checkcommon) == count($checkcommon))
{
$errormsg = "All the same";
}
else
{
$errormsg = "not the same";
}
有没有人可以帮助我?...
答案 0 :(得分:3)
您可以array_unique()
与count()
进行核对: -
if(count(array_unique($checkcommon)) ==1){
echo "All values are same";
}
示例: - https://eval.in/728091