How to check if all values in array are identical?

后端 未结 6 1966
北恋
北恋 2021-01-05 09:42

In PHP how can I quickly tell if all values in array are identical?

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-05 10:40

    $myArray = array('1','1','1');
    $results = array_unique($myArray);
    if(count($results) == 1)
    {
        echo"all value is duplicates";
    }
    else
    {
        echo"all value is not duplicates";
    }
    

提交回复
热议问题