Seems pretty simple: extract all pid values into their own array, run it through array_unique:

$uniquePids = array_unique(array_map(function ($i) { return $i['pid']; }, $holder));

The same thing in longhand:

$pids = array();
foreach ($holder as $h) {
    $pids[] = $h['pid'];
}
$uniquePids = array_unique($pids);
Answer from deceze on Stack Overflow
🌐
PHP
php.net › manual › en › function.array-unique.php
PHP: array_unique - Manual
Although array_unique is not intended to work with multi-dimensional arrays, it does on 5.2.9. However, it does not for 5.2.5. Beware. ... Here's the shortest line of code I could find/create to remove all duplicate entries from an array and then reindex the keys. <?php // Fruits, vegetables, and other food: $var = array('apple','banana','carrot','cat','dog','egg','eggplant','fish'); $var = array_values(array_unique($var)); ?>
🌐
W3Resource
w3resource.com › php-exercises › php-array-exercise-42.php
PHP Array Exercise: Find unique values from multidimensional array and flatten them in zero depth - w3resource
May 30, 2025 - <?php // Define a function to flatten a multidimensional array function array_flat($my_array) { // Initialize an array to store flattened values $fa = array(); // Initialize a variable to track the recursion depth $l = 0; // Loop through the input array foreach($my_array as $k => $v ) { // Check if the current value is not an array if( !is_array( $v ) ) { // Add the non-array value to the flattened array $fa[] = $v; // Continue to the next iteration continue; } // Increment the recursion depth $l++; // Recursively flatten the nested array $fa = array_flat( $v, $fa, $l ); // Decrement the recur
🌐
ItSolutionstuff
itsolutionstuff.com › post › php-how-to-remove-duplicate-values-from-multidimensional-arrayexample.html
PHP Remove Duplicates from Multidimensional Array Example - ItSolutionstuff.com
May 14, 2024 - In this example i have simple multidimensional array with duplicates values array and i will perform to get only unique values from multidimensional. It is possible by core PHP array_map() and array_unique().
🌐
James' Desk
vijayasankarn.wordpress.com › 2017 › 02 › 20 › array_unique-for-multidimensional-array
array_unique for multidimensional array – James' Desk
November 5, 2018 - Posted in Code Snippets, PHP · Posted on February 20, 2017November 5, 2018 by Vijaya Sankar N · array_unique removes duplicates from only flattened one dimensional array. But still it can be used in a multi-dimensional array with a small work-around. Scenario 1: Remove duplicates from array comparing all keys and values in array ·
🌐
W3Resource
w3resource.com › php-exercises › php-array-exercise-38.php
PHP Array Exercise: Create a multidimensional unique array for any single key index - w3resource
March 30, 2026 - ... <?php // Define a function to filter unique values based on a specified key in a multidimensional array function unique_array($my_array, $key) { $result = array(); // Initialize an empty array to store the unique values $i = 0; // Initialize ...
🌐
Position Is Everything
positioniseverything.net › home › php array unique: learn to remove duplicate values from arrays
PHP Array Unique: How To Obtain Unrepeated Values From Arrays
December 29, 2025 - Although the user-defined functions ... task as well. Hence, a combination of array functions such as array_intersect_key, PHP array_unique, and array_map can help in solving the issue....
🌐
IQCode
iqcode.com › code › php › array-unique-multidimensional-php
array_unique multidimensional php Code Example
October 20, 2021 - <?php function super_unique($array,$key) { $temp_array = []; foreach ($array as &$v) { if (!isset($temp_array[$v[$key]])) $temp_array[$v[$key]] =& $v; } $array = array_values($temp_array); return $array; } $arr=""; $arr[0]['id']=0; $arr[0]['titel']="ABC"; $arr[1]['id']=1; $arr[1]['titel']="DEF"; $arr[2]['id']=2; $arr[2]['titel']="ABC"; $arr[3]['id']=3; $arr[3]['titel']="XYZ"; echo "<pre>"; print_r($arr); echo "unique*********************<br/>"; print_r(super_unique($arr,'titel')); ?> ... Array ( &nbsp;&nbsp;&nbsp;&nbsp;[0] =&gt; Array &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;( &nbsp;&nb
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 7530927 › php-getting-unique-values-from-multidimensional-array-inside-a-multidimensional
PHP Getting unique values from multidimensional array inside a multidimensional array - Stack Overflow
Here is what I've been trying with no dice: Copy $tmp = array (); foreach ($a as $row) if (!in_array($row,$tmp)) array_push($tmp,$row); print_r ($tmp); ... Save this answer. ... Show activity on this post.
🌐
AmazingAlgorithms
amazingalgorithms.com › snippets › php › extracting-unique-values-from-a-multidimensional-array
PHP for extracting unique values from a multidimensional array
<?php // Define a multidimensional array $array = [ ['foo', 'bar', 'baz'], ['baz', 'qux', 'foo'], ['bar', 'foo', 'quux'] ]; // Create a new array to store the unique values $uniqueValues = []; // Iterate over the multidimensional array foreach ($array as $subArray) { // Iterate over each sub-array ...
🌐
GitHub
gist.github.com › mistic100 › 8356974
[PHP] Extract unique values of the specified key in a two dimensional array · GitHub
[PHP] Extract unique values of the specified key in a two dimensional array - array_unique_deep.php
Top answer
1 of 5
1

Here is my revised code given your comment and a DEMO of it working as expected. ( http://codepad.org/CiukXctS )

<?php

$tmp = array();
foreach($array as $value)
{
    // just for claraty, let's set the variables
    $val1 = $value[0];
    $val2 = $value[1];
    $found = false;
    foreach($tmp as &$v)
    {
        // check all existing tmp for one that matches
        if(in_array($val1, $v) OR in_array($val2, $v))
        {
            // this one found a match, add and stop
            $v[] = $val1;
            $v[] = $val2;
            // set the flag
            $found = true;
            break;
        }
    }
    unset($v);

    // check if this set was found  
    if( ! $found)
    {
        // this variable is new, set both
        $tmp[] = array(
                $val1,
                $val2,
                );
    }
}

// go trough it all again to ensure uniqueness
$array = array();
foreach($tmp as $value)
{
    $array[] = array_unique($value); // this will eliminate the duplicates from $val2
}

ORIGIN ANSWER

The question is badly asked, but I'll attempt to answer what I believe the question is.

You want to gather all the pairs of arrays that have the same first value in the pair correct?

$tmp = array();
for($array as $value)
{
    // just for claraty, let's set the variables
    $val1 = $value[0];
    $val2 = $value[1];

    if(isset($tmp[$val1])) // we already found it
    {
        $tmp[$val1][] = $val2; // only set the second one
    }
    else
    {
        // this variable is new, set both
        $tmp[$val1] = array(
            $val1,
            $val2,
        );
    }
}
// go trough it all again to change the index to being 0-1-2-3-4....
$array = array();
foreach($tmp as $value)
{
    $array[] = array_unique($value); // this will eliminate the duplicates from $val2
}
2 of 5
0

Here is solution for common task.

$data = array(array(17,99), array(17,121), array(99,77), array(45,51), array(45,131));
$result = array();
foreach ($data as $innner_array) {
    $intersect_array = array();
    foreach ($result as $key => $result_inner_array) {
        $intersect_array = array_intersect($innner_array, $result_inner_array);
    }
    if (empty($intersect_array)) {
        $result[] = $innner_array;
    } else {
        $result[$key] = array_unique(array_merge($innner_array,     $result_inner_array));
    }

}
var_dump($result);