Hello Xinchen,
I have noticed two more cases where we could easily use packed arrays.
- array_merge($packed1, $packed2, ...):
In the quite common case where all arguments are packed arrays, the resulting array can also be a packed array (as per documentation: "if the input arrays [...] contain numeric keys, the later value will not overwrite the original value, but will be appended"), thereby ensuring that packed arrays stay packed when appended to one another.
In general we should try to preserve the packed characteristics wherever possible.
- array_column($input, $column_key, $index_key=null):
For the common case when $index_key=null, we can just create a packed array.
Also (not related to packing), we could pre-initialize the return_value array size with array_init_size() if, and only if, $column_key=null.
Please let me know your thoughts.
Thanks,
Ben
--
Bejamin Coutu
ben.coutu@zeyos.com
ZeyOS, Inc.
http://www.zeyos.com