Sample code for 30+ languages & platforms
PHP Requires Chilkat v11.0.0+

Copy JSON Object from one JSON Array to Another

See more JSON Examples

Demonstrates how to copy an object in a JSON array to another JSON array.

Chilkat PHP Downloads

PHP
<?php

use Chilkat2\JsonArray;
use Chilkat2\JsonObject;

$arr1 = new JsonArray();
$arr2 = new JsonArray();

$s = '[{"a":1}, {"b":2}, {"c":3}]';
$sEmpty = '[]';

$arr1->Load($s);
$arr2->Load($sEmpty);

$jObj = new JsonObject();
$arr1->ObjectAt2(1, $jObj);

$arr2->AddObjectCopyAt(-1, $jObj);

echo $arr2->Emit(), "\n";

// output is:   [{"b":2}]