且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在多维数组中获取唯一值

更新时间:2022-01-17 22:41:59

看起来很简单:将所有 pid 值提取到自己的数组中,通过 array_unique 运行:

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

同样的东西:

$pids = array();
foreach ($holder as $h) {
    $pids[] = $h['pid'];
}
$uniquePids = array_unique($pids);