0

I have 2 Json PHP URL and need to merge into 1.

1st Json PHP URL - completehouse.php

    [
{
          "G": "7TH DIVISION",
          "G1": "2031892",
          "DOOR": "8907",
          "AA": "81",
          "AI": "8745524"
        },
{
          "G": "8TH DIVISION",
          "G1": "4526892",
          "DOOR": "8877",
          "AA": "85",
          "AI": "8759544"
        }
      ]

2nd Json PHP URL - completeflat.php

{
  "Error": "",
  "ErrorCode": 0,
  "Guid": "",
  "Id": 0,
  "Success": true,
  "Value": [
    {
              "G": "6TH DIVISION",
              "G1": "6058974",
              "DOOR": "1245",
              "AA": "67",
              "AI": "6872145"
            },
    {
              "G": "5TH DIVISION",
              "G1": "5891211",
              "DOOR": "1246",
              "AA": "68",
              "AI": "5100214"
            }
          ]

}

What I need is to merge these 2 file and get in completebuilding.php

Desired Output

    {
  "Error": "",
  "ErrorCode": 0,
  "Guid": "",
  "Id": 0,
  "Success": true,
  "Value": [
    {
      "G": "6TH DIVISION",
      "G1": "6058974",
      "DOOR": "1245",
      "AA": "67",
      "AI": "6872145"
    },
    {
      "G": "5TH DIVISION",
      "G1": "5891211",
      "DOOR": "1246",
      "AA": "68",
      "AI": "5100214"
    },
    {
      "G": "7TH DIVISION",
      "G1": "2031892",
      "DOOR": "8907",
      "AA": "81",
      "AI": "8745524"
    },
    {
      "G": "8TH DIVISION",
      "G1": "4526892",
      "DOOR": "8877",
      "AA": "85",
      "AI": "8759544"
    }
  ]
}

Currently I am using following code in completebuilding.php :

<?php

$user[] = json_decode(file_get_contents("completehouse.php"), true);
$user[] = json_decode(file_get_contents("completeflat.php"), true);
$json_merge = json_encode($user);

header('Content-Type: application/json');
echo $json_merge;
?>

But not getting desired output instead I getting different. Help me to save my time from manual merge.

6
  • you can use aray_merge php.net/manual/en/function.array-merge.php Commented Dec 30, 2019 at 20:48
  • 1
    $completeFlat['Value'] = array_merge($completeFlat['Value'], $completeHouse); Commented Dec 30, 2019 at 20:48
  • @MonkeyZeus can you please write the full code of completebuilding.php to get desired output in json format Commented Dec 30, 2019 at 21:20
  • I just answered this very question less than a week ago. Commented Dec 31, 2019 at 0:19
  • @AlexBarker I am not getting exact output as above. Can you please give the correct code. See the code I have used. Commented Dec 31, 2019 at 4:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.