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

JSON AppendArray2 Example

Demonstrates the AppendArray2 function.

Chilkat PHP Extension Downloads

PHP Extension
<?php

include("chilkat.php");

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

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

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

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

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

?>