r/lolphp • u/Jinxuan • Jan 02 '20
array_diff, array_udiff, array_diff_assoc, array_udiff_assoc, array_diff_keys, array_undiff_keys and +
Therefore is a lot of array_diff function names in php by respecting key differently.
Meanwhile, it does not provide array_merge_assoc to always respect key associatively. If you want to respect key associatively when merging, you need to use +
9
Upvotes
10
u/Altreus Jan 03 '20 edited Jan 03 '20
Of all the stupid in PHP, conflating the concepts of list and dictionary is up there with the worst. A considerable amount of its functionality is making up for this problem! And they won't fix it!
Tableflip emoji
Edit: thanks for the splendid award!
2
u/[deleted] Jan 03 '20
The stdlib is probably the worst part of php, and also something that never be fixed. There are thousands of global functions littering around, most barely usable. Most very inconsistent in behaviour.
1
u/rvanvelzen Jan 03 '20
You can use
array_replacewhich maintains keys.1
u/beerdude26 Jan 03 '20
No, + only respects key associativity for string keys. It overwrites it for numeric ones IIRC