In PHP, how can I quickly determine if all values ββin an array are identical?
You can use the test:
count(array_unique($arr)) == 1;
Alternatively, you can use the test:
$arr === array_fill(0,count($arr),$arr[0]);
$results = array_unique($myArray); if(count($results) == 1){ // $myArray is all duplicates }
You can also use this check:
count(array_count_values($arr)) == 1
Why not just iterate over this array?
$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"; }
Carry out a test run and check if all the results match:
foreach ($array as $newarray){ echo $newarray. ''; }
You can check count(array_intersect($arr1, $arr2)) == 0
count(array_intersect($arr1, $arr2)) == 0