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

JSON AppendArray2 Example

Demonstrates the AppendArray2 function.

Chilkat PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\JsonArray;
use Chilkat2\JsonObject;

$json = new JsonObject();
$json->Load('{ "name": "John", "marbles": 100 }');

// Append an empty array named "xyz"
$jarr = new JsonArray();
$json->AppendArray2('xyz', $jarr);

echo $json->Emit(), "\n";
// Expected output is:   {"name":"John","marbles":100,"xyz":[]}

// Add elements to the array.
$jarr->AddStringAt(-1, 'hello');
$jarr->AddIntAt(-1, 256);

echo $json->Emit(), "\n";
// Expected output is:  {"name":"John","marbles":100,"xyz":["hello",256]}