How to get unique value in multidimensional array
try this
foreach($arr as $key => $val) {
$new_arr[] = $val['pid'];
}
$uniq_arr = array_unique($new_arr);
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);
In php >= 5.5 you can use array_column:
array_unique(array_column($holder, 'pid'));
Just iterate over it and apply an array_unique
on the result:
foreach($holder as $yourValues){
$pids[] = $yourValues['pid'];
}
$yourUniquePids = array_unique($pids);