5 ms·
PHP developers differentiate between arrays and associative arrays. Although you can mix int and string keys, I've never seen anyone do so in actual code.
by totony 5y ago
PHP developers differentiate between arrays and associative arrays. Although you can mix int and string keys, I've never seen anyone do so in actual code.
- notRobot 5y agoSame. Been using PHP for years, and I've never come across this in the wild. Just because you can do something, doesn't mean you have to.
- duskwuff 5y agoPHP 8.1 even has a function to tell the difference between list-like arrays and associative arrays: array_is_list().
- edudobay 5y agoThough we cannot force PHP to interpret keys as strings if they also represent valid integers. I just had a case of an (associative) array of numeric codes — those which start with a '0' are treated as string keys, all others being treated as numeric. This doesn't matter so much at runtime, but I had to suppress some type checker (Psalm) errors.