How to get unique value in multidimensional array

前端 未结 8 1223
盖世英雄少女心
盖世英雄少女心 2020-12-01 03:34

I have done a lot of looking around on the overflow, and on google, but none of the results works for my specific case.

I have a placeholder array called $holder, va

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 04:24

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

提交回复
热议问题