久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在多維數組中獲取唯一值

How to get unique value in multidimensional array(如何在多維數組中獲取唯一值)
本文介紹了如何在多維數組中獲取唯一值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在溢出和谷歌上做了很多環顧四周,但沒有一個結果適用于我的具體情況.

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模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 国产va在线观看 | av片网站 | 国产精品一区二区三区免费 | 岛国av噜噜噜久久久狠狠av | 五月天婷婷影院 | a视频 | www4h| 九九天堂 | 超碰免费观看 | 久久综合激情 | 国产精品久久久久久久免费看 | 欧美日韩中文字幕在线观看 | 色爽| 国产美女精品 | 日韩三级精品 | 国产又粗又长又爽 | 99热综合| 天天躁日日躁bbbbb | 色综合久久天天综合网 | 欧美日韩一区二区三区 | 天堂中文av | av网站免费观看 | 亚洲综合影院 | 在线色网站 | 玖草视频 | 玖玖在线视频 | 亚洲一区二区三区在线播放 | 成人免费看片视频 | 在线不卡一区 | 亚洲成人黄色 | 精品久久免费视频 | 国产综合久久 | 久久久久久久久久国产精品 | 人人澡人人爽 | 国产一区二区视频在线观看 | 日本中文在线观看 | 中文字幕av一区二区三区谷原希美 | 国产精品片 | 九九热这里只有 | 91亚洲国产成人久久精品网站 | 中国免费毛片 |