From the course: PHP Tips, Tricks, and Techniques

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Unpacking arrays in PHP 7.1

Unpacking arrays in PHP 7.1

- [David] Hi, I'm David Powers, and welcome to this week's edition of PHP Tips, Tricks, and Techniques designed to help you become a smarter, more productive PHP developer. In PHP, we spend a lot of time working with arrays. They come from a variety of sources including database queries and JSON data feeds, not to mention arrays hard coded into your scripts. In this edition, I want to look at some cool syntax changes in PHP 7.1 that simplify unpacking information from both indexed and associative arrays. Let's start with an indexed array. If you want to follow along, grab the exercise files for this video. In this example, I'm using the foreach loop that begins on line nine to display the elements of this indexed array in an unordered list, and the results are over here. But using the index of each array element to display them makes the code difficult to understand. By the way, this backslash here in front of the first of the two dollar signs is an escape sequence to display a…

Contents