Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Frank de Jonge:
Array destructuring in PHP
May 01, 2018 @ 14:48:15

Frank de Jonge has a post to his site sharing some helpful hints around the use of arrays in PHP. In this quick post he covers some of the array "superpowers", list assignments and nested destructuring.

One of the things I like the most about JavaScript, and PHP also to some extent, is how flexible and expressive they CAN be (but not always are). I also believe that JavaScript, PHP, and Python have a number of features that make them a good fit for serving the forefront of the web.

[...] The most versatile type of PHP, to me, is the array. The array can be used to act like many different classic data types. You can use them as a List, a Set (although that requires some specific handling), a HashMap, just to name a few.

He starts with the "superpowers" that arrays gained in PHP 7.1 (the square bracket syntax for destructuring) and some code examples showing it in action. He then moves on to show how this update works for list assignment. He finishes up the list with a look at nested destructuring and referencing values from subarrays with this same square bracket syntax.

tagged: array destructure language square bracket php71 tutorial

Link: https://blog.frankdejonge.nl/array-destructuring-in-php/


Trending Topics: