使用php

时间:2017-02-01 04:04:47

标签: php arrays mysqli

如何以简单的方式检查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";
}

有没有人可以帮助我?...

1 个答案:

答案 0 :(得分:3)

您可以array_unique()count()进行核对: -

if(count(array_unique($checkcommon)) ==1){
   echo "All values are same";
}

示例: - https://eval.in/728091

参考: - http://php.net/manual/en/function.array-unique.php

相关问题