Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compare same array values

What is the best way to compare elments in the same array in PHP, so that if there are two elemets with the same values in array A, I can pass a function as argument to do somthing ?

like image 898
ahmad Avatar asked Aug 13 '26 21:08

ahmad


1 Answers

You can use array_count_values and in_array functions as:

if(in_array(2,array_count_values($array)) {
  // do something
}
like image 138
codaddict Avatar answered Aug 15 '26 13:08

codaddict



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!