-3
我有2個陣列如下所示,如果我想array[0]
和array[1]
ht_cat_name
是相同的。所以ht_category
是2陣列常見的。所以ht_category基於合併ht_amenity_name。如何合併陣列
Array
(
[0] => Array
(
[ht_amenity_id] => 1
[ht_amenity_name] => Central Air Conditioning
[ht_category] => 1
[ht_cat_name] => General
)
[1] => Array
(
[ht_amenity_id] => 2
[ht_amenity_name] => Facilities for disabled guests
[ht_category] => 1
[ht_cat_name] => General
)
[2] => Array
(
[ht_amenity_id] => 3
[ht_amenity_name] => Climate control
[ht_category] => 2
[ht_cat_name] => Services
)
)
我想合併這樣的設施名稱。
Array
(
[0] => Array
(
[ht_amenity_id][0] => 1
[ht_amenity_id][1] => 2
[ht_amenity_name][0] => Central Air Conditioning
[ht_amenity_name][1] => Facilities for disabled guests
[ht_category] => 1
[ht_cat_name] => General
)
[1] => Array
(
[ht_amenity_id] => 3
[ht_amenity_name] => Climate control
[ht_category] => 2
[ht_cat_name] => Services
)
)
哪裏是代碼,你試過嗎?請添加您爲此嘗試的代碼.... – Vickrant
$ amen = DB :: select(「SELECT'h'.'ht_amenity_id','h'.'ht_amenity_name','h'.'ht_category','a '.'ht_cat_name' FROM'abserve_hotel_amenities' as'h'將abserve_hotel_categories加入'a' ON'a'.'ht_cat_id' ='h'.'ht_category'「); \t \t \t $ am = array(); \t \t \t的foreach($阿門爲$密鑰=> $值){ \t \t \t $是[] =(get_object_vars($值)); \t \t \t} \t \t \t $用戶=陣列(); \t \t \t的foreach($的空房爲$密鑰=> $值){ \t \t \t $用戶[] =(get_object_vars($值)); \t \t \t} – murugesh
sry,$ amen = DB :: select(「SELECT'h'.ht_amenity_id','h'.ht_amenity_name','h'.ht_category','a'.'ht_cat_name' FROM 'abserve_hotel_amenities' as'h'將abserve_hotel_categories加入'a' ON'a'.'ht_cat_id' ='h'。'ht_category'「); \t \t \t $ AM =陣列(); \t \t \t的foreach($阿門爲$密鑰=> $值){ \t \t \t $是[] =(get_object_vars($值) ); \t \t \t} \t \t \t $用戶=陣列(); \t \t \t的foreach($的空房爲$密鑰=> $值){ \t \t \t $ user [] =(get_object_vars($ value)); \t \t \t} – murugesh