arrays - Merge two 2 Dimensional json in php -
i have 2 two dimensional json.
[{"4":"213231.jpg"},{"5":"cadbury 5 star chocolate.jpg"}] [{"1":"slider-1.png"},{"2":"slider-2.png"},{"3":"slider-3.png"},{"4":"slider-4.png"},{"5":"slider-5.png"}]
i want merge 2 arrays , want answer
[{"1":"slider-1.png"},{"2":"slider-2.png"},{"3":"slider-3.png"},{"4":"213231.jpg"},{"5":"cadbury 5 star chocolate.jpg"}]
try following:
$json1 = '[{"1":"slider-1.png"},{"2":"slider-2.png"},{"3":"slider-3.png"},{"4":"slider-4.png"},{"5":"slider-5.png"}]'; $json2 = '[{"4":"213231.jpg"},{"5":"cadbury 5 star chocolate.jpg"}]'; echo json_encode(array_merge(json_decode($json1), json_decode($json2)));
output
[{"1":"slider-1.png"},{"2":"slider-2.png"},{"3":"slider-3.png"},{"4":"slider-4.png"},{"5":"slider-5.png"},{"4":"213231.jpg"},{"5":"cadbury 5 star chocolate.jpg"}]
Comments
Post a Comment