merge two json in php

Solutions on MaxInterview for merge two json in php by the best coders in the world

showing results for - "merge two json in php"
Selim
08 Jan 2018
1<?php
2$json1 = '{"id": "GD01", "name": "Garrett Davidson", "position": "System Administrator", "location": "New York"}';
3$json2 = '{"id": "DW02", "name": "Donna Winters", "position": "Senior Programmer", "location": "Seattle"}';
4
5// decode json to array
6$array[] = json_decode($json1, true);
7$array[] = json_decode($json2, true);
8
9// encode array to json
10$result = json_encode($array, JSON_PRETTY_PRINT);
11
12// print merged json
13header('Content-type: text/javascript');
14echo $result;
15?>
16