Hi Riikka Kalliomäki, > Another similar problem with creating array copies is the detection of > "indexed" arrays (as opposed to associative arrays). Particularly when > dealing with JSON, it's a common need to detect if an array has keys > from 0 to n-1 and in that order. My understanding is that at least in > some cases this would be trivial and fast to tell internally in PHP, > but the functionality is not exposed to userland. > > Current common practices include for example: > > array_keys($array) === range(0, count($array) - 1) > > Memory optimized way of dealing with this is via foreach, but it's > quite cumbersome and again, you must not use array_keys in the > foreach. The following example demonstrates that the worst case > scenario triples the memory usage using range: https://3v4l.org/FiWdk
This was brought up in https://externals.io/message/109760#109795 there's a PR against php-src but there was some discussion about whether php should strive to add an actual "list" type instead and what it should be named - https://github.com/php/php-src/pull/4886 I'm fairly certain is_list() would have to go through the RFC process given the proposals for alternate approaches or alternate names Cheers, - Tyson -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php