check if all values in array are equal php
if(count(array_unique($array)) === 1) {
// all values in $array are the same
} else {
// at least 1 value in $array is different
}1. Check if all values are equal without knowing the values from array:
$array = array('true', 'true', 'true');
if((count(array_unique($array)) === 1)) {
echo "all equal";
} else {
echo "not equal";
}
2. Check if all values are equal when you know the value from array:
- In this case we know the equal value should be "true"
$array = array('true', 'true', 'true');
if (count(array_unique($array)) === 1 && end($array) === 'true') {
}if(count(array_unique($array, SORT_REGULAR)) < count($array)) {
// $array has duplicates
} else {
// $array does not have duplicates
}
Also in PHP:
- catch new exception php
- create new seeder laravel
- check if word matches with string
- How do you clear cache in Laravel?
- Warning: sprintf(): Too few arguments in /opt/lampp/htdocs/wordpress/wp-admin/includes/class-bulk-upgrader-skin.php on line 152
- display error reporting
- codeigniter.com cart
- Allowed memory size of 1610612736 bytes exhausted
- USA format date in php
- css date function
- dateformat j/m/a php
- change the format of date c#
- clear config cache laravel
- aadd day in date php
- create project with laravel 7
- create a new laravel 8 project
- consolelog php response
- check email exist or not wordpress
- extract data from api callback php
- php auto refresh page
- apt install php7.4-mysql
- Error: Cannot redeclare composerRequire1d8e02dff94f518b7a14ddcb6710f10d() (previously declared in /Applications/XAMPP/xamppfiles/htdocs/all4learn2/Vendor/composer/autoload_real.php:66)
- array_unique() on value php
- ternary if in blade