How to merge two arrays

how to merge two arrays, put the remark corresponding to id in data2 into the id corresponding to data1, and the final result is data3

const data1 = [
    { "id": 1, "url": "1111" },
    { "id": 2, "url": "111" },
    { "id": 3, "url": "22222" },
    { "id": 4, "url": "222" },
    { "id": 5, "url": "2222" },
    { "id": 6, "url": "22222" }
]
const data2 = [
    { "id": 1, "remark": "1" },
    { "id": 2, "remark": "2" },
    { "id": 3, "remark": "" },
    { "id": 4, "remark": "" },
    { "id": 5, "remark": "" },
    { "id": 6, "remark": "beizhu6" }
]
function fun(arr1, arr2) {
    arr1.map(item => {
        arr2.map(item2 => {
            if (item.id == item2.id) {

            }
        });
    });
    arr2 = [];
    return arr1
}
fun(data1,data2);

data3=[
    { "id": 1, "url": "1111", "remark": "1" },
    { "id": 2, "url": "111", "remark": "2" },
    { "id": 3, "url": "22222", "remark": "" },
    { "id": 4, "url": "222", "remark": "" },
    { "id": 5, "url": "2222", "remark": "" },
    { "id": 6, "url": "22222", "remark": "beizhu6" }
]
Mar.12,2021


<?php
$data1 = '[{"id":1,"url":"1111"},{"id":2,"url":"111"},{"id":3,"url":"22222"},{"id":4,"url":"222"},{"id":5,"url":"2222"},{"id":6,"url":"22222"}]';
$data2 = '[{"id":1,"remark":"1"},{"id":2,"remark":"2"},{"id":3,"remark":""},{"id":4,"remark":""},{"id":5,"remark":""},{"id":6,"remark":"beizhu6"}]';
$data1 = json_decode($data1,true);
$data2 = json_decode($data2,true);
echo json_encode(array_merge_recursive($data1, $data2));

system functions are easy to handle

Menu