PHP Get Keys of Duplicate Values in Array

03-Apr-2023

.

Admin

PHP Get Keys of Duplicate Values in Array

Hi Dev,

In this tutorial, I will show you PHP get keys of duplicate values in the array. you'll learn how to get all keys with the same value in PHP array. I’m going to show you about how to find all keys with the same value in PHP array. let’s discuss about PHP find keys of duplicate values in the array.

Now, let's see post of PHP get keys of duplicate values in the array. this example will help you how to get all keys with the same value in PHP array. let’s discuss about how to find all keys with the same value in PHP array. I explained simply step by step PHP find keys of duplicate values in the array.

Example:


index.php

<?php

$array = array('a' => 100, 'b' => 1, 'c' => 100, 'd' => 10);

$counts = array_count_values($array);

$filtered = array_filter($array, function ($value) use ($counts) {

return $counts[$value] > 1;

});

var_dump($filtered);

?>

Output:

array(2) {

["a"]=>

int(100)

["c"]=>

int(100)

}

I hope it could help you...

#PHP