的數組下面是我的工作對數組的一個例子:刪除重複陣列,從陣列
Array
(
[0] => Array
(
[id] => 1331
[shortname] => MCS-115-113C
[userid] => 663
[email] => [email protected]
[username] => FOOBARBAZ
[nombrecompleto] => asdfasdf
[lastlogin] => 1367501486
)
[1] => Array
(
[id] => 1331
[shortname] => MAFA-EOOF
[userid] => 323
[email] => [email protected]
[username] => FOOBARBAZ
[nombrecompleto] => asdfasdf
[lastlogin] => 136732186
)
[2] => Array
(
[id] => 1331
[shortname] => MKT-FOOBAR
[userid] => 434
[email] => [email protected]
[username] => adsfasdf
[nombrecompleto] => asdfasdf
[lastlogin] => 1367234486
)
在我的情況,我想在數組中的元素username
比較和刪除重複。
因此,在這種情況下,我只會返回兩個元素,用戶名和FOOBARBAZ
adsfasdf
:
Array
(
[0] => Array
(
[id] => 1331
[shortname] => MAFA-EOOF
[userid] => 323
[email] => [email protected]
[username] => FOOBARBAZ
[nombrecompleto] => asdfasdf
[lastlogin] => 136732186
)
[1] => Array
(
[id] => 1331
[shortname] => MKT-FOOBAR
[userid] => 434
[email] => [email protected]
[username] => adsfasdf
[nombrecompleto] => asdfasdf
[lastlogin] => 1367234486
)
我怎樣才能做到這一點在PHP?
你有看'array_unique()'? – 2013-05-05 02:46:45
如果這個數組來自一個查詢,我會建議在SQL中解決這個問題,以減少sql和php之間的流量。 – 2013-05-05 02:48:39