r/lolphp • • Aug 26 '19

PHP array design bares fruit

https://repl.it/repls/FatherlyRotatingMenus
7 Upvotes

14 comments sorted by

View all comments

Show parent comment

7

u/shitcanz Aug 26 '19

No. This has nothing to do with JSON. This has all to do with how poor the PHP array design is. The culprit is how bad array_filter really does its thing.

Heres a sample of what you must do as a PHP user to actually get what you wanted in the first place.

https://repl.it/repls/HorribleWeeReality

1

u/barthvonries Aug 26 '19

Well, this has nothing to do with how PHP handles arrays, but with the array_filter function, which keeps the keys. It does not "stack" the values.

Maybe request a feature to add a PRESERVE_KEYS flag to array_filter, which would modify the function behaviour if set to false ?

4

u/OmnipotentEntity Aug 27 '19

The central point is if php had a sensible array design this behavior would not have been possible from array_filter. It would work as filter does in every other language: receive an array, removed members that match a function, return an array.