- array_fill_keys: documentation ( source)
- json_encode: documentation ( source)
- range: documentation ( source)
<?php
$ar1 = [];
$ar1[3] = 4; $ar1[2] = 3; $ar1[5] = 6;
echo json_encode($ar1) . PHP_EOL;
$ar2 = array_fill_keys(range(0, 9), null);
$ar2[3] = 4; $ar2[2] = 3; $ar2[5] = 6;
echo json_encode($ar2) . PHP_EOL;
$ar3 = new \SplFixedArray(10);
$ar3[3] = 4; $ar3[2] = 3; $ar3[5] = 6;
echo json_encode($ar3) . PHP_EOL;