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.

Understanding the splat operator

Understanding the splat operator

- [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. The splat operator, what on earth is that? This is what it looks like, it's three dots preceding a variable. The splat operator has been around since August, 2014. It was introduced in PHP 5.6 and it's used in two scenarios. When defining a function preceding the final parameter in the function signature with the splat operator allows the function to accept an arbitrary number of arguments, to use the technical term, it creates a variadic function. When invoking a function preceding an argument with the splat operator unpacks an array and assigns each element to the function's parameters in the same order as then appear in the array. It's this aspect of breaking an array apart that gives the splat operator its name, although some people call it the scatter or spread operator. It's useful because it greatly simplifies…

Contents