title: PHP json_decode question
body: <p>i'm trying to use json_decode to combine a few json objects and then re-encode it. my json looks like:</p>
  
  <pre><code>{
      "core": {
          "segment": [
              {
                  "id": 7,
                  "name": "test1" 
              },
              {
                  "id": 4,
                  "name": "test2" 
              } 
          ] 
      }
  }
  </code></pre>
  
  <p>i have a few of these json objects and would like to combine only the "segement"  arrays for each to get something like this:</p>
  
  <pre><code>{
      "segment": [
          {
              "id": 7,
              "name": "test1" 
          },
          {
              "id": 4,
              "name": "test2" 
          } 
      ],
      "segment": [
          {
              "id": 5,
              "name": "test3" 
          },
          {
              "id": 8,
              "name": "test4" 
          } 
      ]
  }
  </code></pre>
  
  <p>right now in my php code, i'm decoding the json, storing each "segment" array into a string, and then encoding the json.</p>
  
  <pre><code>public function handleJSON($json){
          $decodeData = json_decode($json);
          $segment =$decodeData-&gt;core;
          return $segment;
  }
  
  public function formatJSON(){
          $segments = "";
      for ($i = 0; $i &lt; count($json);$i++)
          {
            $segments .= handleJSON($json[$i]);
          }
      echo json_encode($segments);
  }
  </code></pre>
  
  <p>when i do this, i receive an error :
  Object of class stdClass could not be converted to string </p>
  
  <p>so then i tried using storing them in an array: </p>
  
  <pre><code>public function formatJSON(){
          $segments = array();
      for ($i = 0; $i &lt; count($json);$i++)
          {
            $segments[$i] = handleJSON($json[$i]);
          }
      echo json_encode($segments);
  }
  </code></pre>
  
  <p>this time, i don't get an error, but it stores my entire combined json object in array brackets. how can i have it just return the JSON object, without being encapsulated in an array?</p>