我想在特定区域的detail array
中插入data array
。
例如,bdh
中detail array
键的值应放在bdh
的{{1}}键中,替换那里的空数组首先。同样,data array
中hadoop
键的值应替换detail array
当前所拥有的hadoop
键的空数组。对data array
数组中的每个键都应该进行此替换。
我如何做到这一点?
数据阵列
details
详情数组
{"data":
{
"categories":
{
"articles":
{
"bdh":[],
"hadoop":[]
},
"videos":
{
"bdh Videos":[],
"hadoop Videos":[]
}
}
}
}
答案 0 :(得分:0)
<?php
$videos = '
{"data":
{
"categories":
{
"articles":
{
"bdh":[],
"hadoop":[]
},
"videos":
{
"bdhVideos":[],
"hadoopVideos":[]
}
}
}
}
';
$details='
{"details":{
"bdh":
[
{"id":1, "name":"bdh article 1", "body":"this is bdh article 1 body."},
{"id":2, "name":"bdh article 2", "body":"this is bdh article 2 body."}
],
"hadoop":
[
{"id":3, "name":"hadoop article 1", "body":"this is hadoop article 1 body."},
{"id":4, "name":"hadoop article 2", "body":"this is hadoop article 2 body."}
],
"bdhVideos":
[
{"id":5, "name":"bdh videos 1", "body":"this is bdh videos 1 body."},
{"id":6, "name":"bdh videos 2", "body":"this is bdh videos 2 body."}
],
"hadoopVideos":
[
{"id":7, "name":"hadoop videos 1", "body":"this is hadoop videos 1 body."},
{"id":8, "name":"hadoop videos 2", "body":"this is hadoop videos 2 body."}
]
}
}
';
$arr_videos = json_decode($videos);
$arr_details = json_decode($details);
//bdh
$arr_videos->data->categories->articles->bdh = $arr_details->details->bdh[0];
//hadoop
$arr_videos->data->categories->articles->hadoop = $arr_details->details->hadoop[0];
//videos bdh
$arr_videos->data->categories->videos->bdh = $arr_details->details->bdhVideos;
//videos hadoop
$arr_videos->data->categories->videos->hadoop = $arr_details->details->hadoopVideos;
print_r($arr_videos);
?>