- json_encode: documentation ( source)
<?php
$a= [];
$b = 'foo';
$c = 'bar';
$a[$b][$c][] = 1;
echo "Assign to left-hand side:";
print_it($a,$b,$c);
echo "Assign via byref call:";
byref($a[$b][$c]);
print_it($a,$b,$c);
function byref(&$x) {
$x[]= 2;
}
function print_it($a,$b,$c) {
echo "\n";
echo "\n" . json_encode($a);
echo "\n" . json_encode($a[$b]);
echo "\n" . json_encode($a[$b][$c]);
echo "\n\n";
}