Check if all values in array are the same

前端 未结 8 877
生来不讨喜
生来不讨喜 2020-12-02 22:17

I need to check if all values in an array equal the same thing.

For example:

$allValues = array(
    \'true\',
    \'true\',
    \'true\',
);
         


        
8条回答
  •  不知归路
    2020-12-02 22:33

    $x = 0;
    foreach ($allvalues as $a) {
       if ($a != $checkvalue) {
          $x = 1;
       }
    }
    
    //then check against $x
    if ($x != 0) {
       //not all values are the same
    }
    

提交回复
热议问题