<?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;
- Output for 8.1.0 - 8.1.29, 8.2.0 - 8.2.23, 8.3.0 - 8.3.11
- {"3":4,"2":3,"5":6}
[null,null,3,4,null,6,null,null,null,null]
[null,null,3,4,null,6,null,null,null,null]
preferences:
57.16 ms | 406 KiB | 5 Q