我處於一種情況下,通過子數組索引創建一個唯一的數組。請參閱此代碼並幫助我解決此問題。基於值的PHP數組唯一子數組
$user=Array(
[1]=>Array(
username => Sujith,
email=>[email protected],
[address] => Array(
[address_id] => 1227
[city] => Ayoor
[state] => Kerala
[Country] => India
)
)
[2]=>Array(
username => Ajith,
email=>[email protected],
[address] => Array(
[address_id] => 1227
[city] => Ayoor
[state] => Kerala
[Country] => India
)
)
[3]=>Array(
username => Akhil,
email=>[email protected],
[address] => Array(
[address_id] => 1228
[city] => Kollam
[state] => Kerala
[Country] => India
)
)
)
我想讓它獨特的由address.address_id.So所得陣列應
$user=Array(
[1]=>Array(
username => Sujith,
email=>[email protected],
[address] => Array(
[address_id] => 1227
[city] => Ayoor
[state] => Kerala
[Country] => India
)
)
[3]=>Array(
username => Akhil,
email=>[email protected],
[address] => Array(
[address_id] => 1228
[city] => Kollam
[state] => Kerala
[Country] => India
)
)
)
我的意思是,每address..Please 1個用戶幫我解決這個..
是的,這是它應該如何工作,因爲沒有內置的功能來執行操作。一起使用array_map和array_unique我們可以得到唯一的address_id,但這需要額外的循環來根據需要生成數組。此外,對於array_filter,您需要額外的循環來生成數組。所以,以簡單的方式,你的答案是相當不錯的! –