array_intersect_key: The Input Whitelist Hiding in the Standard Library
Mass-assignment bugs happen when request data flows unfiltered into updates. Two array functions - intersect_key and diff_key - are the terse, auditable filter.
Step-by-step programming tutorials on PHP, JavaScript, Laravel, WordPress and more.
Mass-assignment bugs happen when request data flows unfiltered into updates. Two array functions - intersect_key and diff_key - are the terse, auditable filter.
"item10" before "item2", "Öl" after "z", uppercase clustering before lowercase - default sorts betray human expectations three different ways. PHP has a fix for each.
Keyed destructuring, foreach unpacking, swaps, nested extraction - the [$a, $b] syntax has quietly become one of PHP's best readability tools.
sort() silently rearranges the original array - a bug factory in shared state. ES2023 shipped non-mutating twins for the worst offenders, plus with() for single-item replacement.
Python has range(), PHP has range() - JavaScript has a weird-looking idiom that does the same and more, once you understand why the mapping callback is built in.
The third parameter turns array_column into a re-indexing tool, it reads object properties, and combined with array_map it handles most of your collection reshaping.
Grouping an array of objects used to mean writing the same reduce() dance in every project. JavaScript finally does it natively, and the syntax is one line.