How to get unique value in multidimensional array

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);

Leave a Comment