PHP: The best way to check if 3 variables are identical?

前端 未结 4 825
逝去的感伤
逝去的感伤 2020-12-11 21:54

Forgive me if this is a common thing but I\'m not sure how I should go about it.

I would like to see if three variables are identical to each other

I thought

4条回答
  •  长情又很酷
    2020-12-11 22:43

    Here's an alternative solution that might be helpful. It will be particularly useful if your variables are already in an array.

    $a = array($one, $two, $three);
    
    if(count(array_unique($a)) == 1){
      // all match
    }
    else {
      // some items do not match
    }
    

提交回复
热议问题