值我有以下的數組:在基座獨特陣列上的特定鍵
Array
(
[0] => Array
(
[hotelID] => 10
[hotelcategoryID] => 12
[hotelName] => Grand Forest Metsovo
[hotelShortDescription] =>
[hotelVisible] => 1
[roomID] => 2
)
[1] => Array
(
[hotelID] => 10
[hotelcategoryID] => 12
[hotelName] => Grand Forest Metsovo
[hotelShortDescription] =>
[hotelVisible] => 1
[roomID] => 3
)
[2] => Array
(
[hotelID] => 10
[hotelcategoryID] => 12
[hotelName] => Grand Forest Metsovo
[hotelShortDescription] =>
[hotelVisible] => 1
[roomID] => 4
)
[3] => Array
(
[hotelID] => 14
[hotelcategoryID] => 7
[hotelName] => Hotel Metropolis
[hotelShortDescription] =>
[hotelVisible] => 1
[roomID] => 23
)
[4] => Array
(
[hotelID] => 14
[hotelcategoryID] => 7
[hotelName] => Hotel Metropolis
[hotelShortDescription] =>
[hotelVisible] => 1
[roomID] => 24
)
)
我有兩個不同hotelID密鑰。我想只提取一個元素(第一個元素),其中hotelID在整個數組中是唯一的。我想用下面的代碼:
$data['uniqueHotels'] = array_map('unserialize', array_unique(array_map('serialize', $hotels)));
但是沒有任何運氣到目前爲止。
任何人都可以給我一個提示嗎?
你的問題不清楚。你在找什麼?一個具有獨特酒店ID的數組?如何處理重複?當hotelID相同時,其他字段是否一樣? (不!) – 2014-09-21 13:46:32
是的,我只想要不同的酒店ID鍵。第一個元素會做。其他元素可能會被釋放。 – user2417624 2014-09-21 13:52:27