【问题标题】:check if multiple value are equal or not equal using php使用php检查多个值是否相等
【发布时间】:2017-06-17 17:22:34
【问题描述】:

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

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

【问题讨论】:

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

标签: php arrays mysqli


【解决方案1】:

你可以通过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

【讨论】:

  • @ivor 很高兴为您提供帮助。
猜你喜欢
  • 2018-09-05
  • 1970-01-01
  • 2023-01-19
  • 1970-01-01
  • 2021-07-16
  • 2015-10-23
  • 1970-01-01
  • 2010-11-16
  • 2015-08-21
相关资源
最近更新 更多