Tools
- Sandbox
- Paste Code
- Snippets
- Generators
- Checks
- Convertors
- Home
- php
- Checks and Validations
- How to check if all values in array are equal in PHP
How to check if all values in array are equal in PHP
Snippet
Share
Do you find this snippet useful? Then share it with your friends or colleagues. This will help us to make our free web tools better.
The easiest way to check the values of an array contain the same value using array_unique and count if all keys are the same this should equal 1.
<?php
$arr = array('test', 'test', 'test');
if (count(array_unique($arr)) === 1) {
echo 'equal';
} else {
echo 'not equal';
}