In the sample, it used the if statement if(count(array_unique($arr)) == 1){} to make checking.
Sample 1:
<?phpResult:
$arr = Array("a","a","a");
if(count(array_unique($arr)) == 1){
echo "all value in array are same";
}else{
echo "Values in array are not equal";
}
?>
Sample 2:
<?phpResult:
$arr = Array("a","a","b");
if(count(array_unique($arr)) == 1){
echo "all value in array are same";
}else{
echo "Values in array are not equal";
}
?>
Reference:
http://stackoverflow.com/questions/2554410/how-to-check-if-all-values-in-array-are-identical
No comments :
Post a Comment