我在溢出和谷歌上做了很多环顾四周,但没有一个结果适用于我的具体情况.
I have done a lot of looking around on the overflow, and on google, but none of the results works for my specific case.
我有一个名为 $holder 的占位符数组,值如下:
I have a placeholder array called $holder, values as follows:
Array (
[0] => Array (
[id] => 1
[pid] => 121
[uuid] => 1
)
[1] => Array (
[id] => 2
[pid] => 13
[uuid] => 1
)
[2] => Array (
[id] => 5
[pid] => 121
[uuid] => 1
)
)
我试图从这个多维数组中提取不同/唯一的值.我想要的最终结果是一个包含 (13,121) 的变量,或者(最好)一个数组,如下所示:大批([0] => 13[1] => 121)
I am trying to pull out distinct/unique values from this multidimensional array. The end result I would like is either a variable containing (13,121), or (preferrably) an array as follows: Array( [0] => 13 [1] => 121 )
我再次尝试序列化等,但不太明白在每个数组中使用单个键操作时它是如何工作的.
Again I've tried serializing and such, but don't quite understand how that works when operating with a single key in each array.
我尽量说清楚.我希望这是有道理的...
I tried to be as clear as possible. I hope it makes sense...
看起来很简单:将所有 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);
这篇关于如何在多维数组中获取唯一值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 SELECT(MYSQL/PHP) 中加入 2 个表Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 个表)
如何使<option selected=“selected">由How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 设置?)
使用 PHP 中的数组自动填充选择框Auto populate a select box using an array in PHP(使用 PHP 中的数组自动填充选择框)
PHP SQL SELECT where like search item with multiple wordsPHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(),名称 ASCMySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名称 ASC)