Looking at the source for PHP, I can see exactly why they did it!
What they do is create the first record in the array. In PHP, it looks like this:
$a = array(-4 => 10);
Then they add each new entry as follows:
$count--; while ($count--) { $a[] = 10; }
If you do this in exactly the same way, you will see the same behavior. A super short PHP script demonstrates this:
<?php $a = array(-4 => "Apple"); $a[] = "Banana"; print_r($a); ?>
Result: Array ( [-4] => Apple [0] => Banana )
Note Yes, I used PHP instead of the C source that they used, since the PHP programmer can understand this much better than the original source. This is about the same effect, however, since they use PHP functions to generate results ...
source share