Home > Mobile >  Check if even one value differs in a Php array
Check if even one value differs in a Php array

Time:10-26

So I have an array of seller ids for ex :

Sellers ( [0] => 1 [1] => 10 )

If incase there were many sellers like hundreds, how do I check if there's (atleast 2) different sellers in the array ? Basically I can't have 2 different seller ids in that array. and if thats the case it should print : "More than 1 seller".

CodePudding user response:

You can use the array_count_values(array $array); function for this

$Sellers = array(10, 10, 10);
$SellersCount = array_count_values($Sellers);
if(count($SellersCount) > 1) {
  echo("More than 1 seller");
}
  • Related