3 ms·
* duct-tape style of arrays that Just Work(tm) as arrays, hash maps, etc. without having to use any boilerplate code. It's the main reason why I still prefer P
by babuskov 5y ago
* duct-tape style of arrays that Just Work(tm) as arrays, hash maps, etc. without having to use any boilerplate code.
It's the main reason why I still prefer PHP for quick&dirty scripting and data processing.
- Navarr 5y agoI love PHP "arrays" but there is one tiny gotcha that becomes more important as we do type-safety stuff more and more. `$a['1'] = 'string';` becomes `$a[1] = 'string';`. This appears to be the case for any fully-fledged decimal number where `(string)(int)$key === $key` So if you are expecting `array_keys` to return all strings, you might get surprised
- dotancohen 5y agoSome years ago I was appending underscores to key strings to avoid that. We're talking PHP 5 era. But even at that time stdClass was available. Today, I much prefer either using a stdClass object or actually making a real class when I reach for an associative array. They still have their use cases, though.