Array ( [0] => Array ( [id] => 9079 [user_id] => 8677 [status] => 3 [context] => [city] => 上海市 [location] => [created_at] => 1631084306 [diamond_reward] => 0 [file_num] => 3 [visible_type] => 1 ) [1] => Array ( [id] => 9077 [user_id] => 9201 [status] => 3 [context] => 哈哈哈哈 [city] => 上海市 [location] => [created_at] => 1628471456 [diamond_reward] => 30 [file_num] => 2 [visible_type] => 1 ) [2] => Array ( [id] => 9076 [user_id] => 9207 [status] => 3 [context] => 刚刚好 [city] => 上海市 [location] => [created_at] => 1628471330 [diamond_reward] => 420 [file_num] => 3 [visible_type] => 1 ) [3] => Array ( [id] => 9072 [user_id] => 8842 [status] => 3 [context] => [city] => 上海市 [location] => [created_at] => 1625377677 [diamond_reward] => 0 [file_num] => 3 [visible_type] => 1 ) [4] => Array ( [id] => 9070 [user_id] => 7883 [status] => 3 [context] => [city] => 上海市 [location] => [created_at] => 1625131169 [diamond_reward] => 0 [file_num] => 3 [visible_type] => 1 ) )
Array ( [0] => Array ( [file_id] => 3B2F0C78-FC6C-5317-9007-9B5968D1CF32.png [type] => 1 [file_url] => 3B2F0C78-FC6C-5317-9007-9B5968D1CF32.png [sort] => 0 [width] => 828 [height] => 1794 [duration] => 0 [moment_id] => 9070 ) [1] => Array ( [file_id] => F6AC3AC5-0DD7-783B-4A6E-98F27AE49C96.png [type] => 1 [file_url] => F6AC3AC5-0DD7-783B-4A6E-98F27AE49C96.png [sort] => 1 [width] => 828 [height] => 1794 [duration] => 0 [moment_id] => 9070 ) [2] => Array ( [file_id] => 8652CE5F-2069-28C1-A992-5C5FF6262F60.png [type] => 1 [file_url] => 8652CE5F-2069-28C1-A992-5C5FF6262F60.png [sort] => 2 [width] => 1104 [height] => 828 [duration] => 0 [moment_id] => 9070 ) [3] => Array ( [file_id] => C63CC0FB-F3AD-D337-75BA-54E7E27D9800.png [type] => 1 [file_url] => C63CC0FB-F3AD-D337-75BA-54E7E27D9800.png [sort] => 0 [width] => 828 [height] => 1794 [duration] => 0 [moment_id] => 9072 ) [4] => Array ( [file_id] => 071FDC1A-5FFB-2C50-592C-2B37EEE2DDE9.png [type] => 1 [file_url] => 071FDC1A-5FFB-2C50-592C-2B37EEE2DDE9.png [sort] => 1 [width] => 828 [height] => 1794 [duration] => 0 [moment_id] => 9072 ) [5] => Array ( [file_id] => 9258ED6A-72BE-59BA-7A18-25F3BD528EEB.png [type] => 1 [file_url] => 9258ED6A-72BE-59BA-7A18-25F3BD528EEB.png [sort] => 2 [width] => 828 [height] => 1794 [duration] => 0 [moment_id] => 9072 ) [6] => Array ( [file_id] => B0D45781-F6A8-5464-636E-F3BEB147D7FA.png [type] => 1 [file_url] => B0D45781-F6A8-5464-636E-F3BEB147D7FA.png [sort] => 0 [width] => 640 [height] => 500 [duration] => 0 [moment_id] => 9076 ) [7] => Array ( [file_id] => 5E3A5A27-A0FD-861B-F43B-5F5C8C215E0F.png [type] => 1 [file_url] => 5E3A5A27-A0FD-861B-F43B-5F5C8C215E0F.png [sort] => 1 [width] => 640 [height] => 881 [duration] => 0 [moment_id] => 9076 ) [8] => Array ( [file_id] => 1858E76E-EBCC-4617-0E9A-8A2DEC2A1646.png [type] => 1 [file_url] => 1858E76E-EBCC-4617-0E9A-8A2DEC2A1646.png [sort] => 2 [width] => 640 [height] => 903 [duration] => 0 [moment_id] => 9076 ) [9] => Array ( [file_id] => D97DE8D2-5EB6-83A5-E8CE-49D66520E01B.png [type] => 1 [file_url] => D97DE8D2-5EB6-83A5-E8CE-49D66520E01B.png [sort] => 0 [width] => 720 [height] => 866 [duration] => 0 [moment_id] => 9077 ) [10] => Array ( [file_id] => 0A57F0E7-A599-871C-EC91-ACA31976D9B5.png [type] => 1 [file_url] => 0A57F0E7-A599-871C-EC91-ACA31976D9B5.png [sort] => 1 [width] => 1104 [height] => 828 [duration] => 0 [moment_id] => 9077 ) [11] => Array ( [file_id] => 1F69EDF7-50EC-4ED6-2980-F0BE751B31B5.png [type] => 1 [file_url] => 1F69EDF7-50EC-4ED6-2980-F0BE751B31B5.png [sort] => 0 [width] => 390 [height] => 366 [duration] => 0 [moment_id] => 9079 ) [12] => Array ( [file_id] => 72CF5D7D-C00A-A9DA-075B-21ED5B4AFCA5.png [type] => 1 [file_url] => 72CF5D7D-C00A-A9DA-075B-21ED5B4AFCA5.png [sort] => 1 [width] => 399 [height] => 369 [duration] => 0 [moment_id] => 9079 ) [13] => Array ( [file_id] => 6AB9B324-95DA-C00D-4B73-706EB1E1EC75.png [type] => 1 [file_url] => 6AB9B324-95DA-C00D-4B73-706EB1E1EC75.png [sort] => 2 [width] => 366 [height] => 354 [duration] => 0 [moment_id] => 9079 ) )
将第二个数组中moment_id与第一个数组中id一致的数据进行归类
第一个数组为:$data1
第二个数组为:$data2
处理方式:
$new_moment_file_list = []; for ($i=0;$i<count($data2);$i++){ $new_moment_file_list[$data2[$i]['moment_id']][] = $data2[$i]; } unset($data2);
foreach ($data1 as $key=>$value){
$data1[$key]['files'] = [];
if(!empty($new_moment_file_list[$value['id']])){
$data1[$key]["files"] = $new_moment_file_list[$value['id']];
}
}