New Array Handling Techniques
Learn about the new array handling methods that help developers perform multiple array operations with very few lines of code.
We'll cover the following
There have been a number of improvements in PHP 8 array- and string-handling techniques. Although there is insufficient space in this course to cover every single enhancement, we will examine the more significant improvements in this lesson.
Working with the array_splice()
method
The array_splice()
function is a cross between substr()
and str_replace()
: it lets us replace a subset of one array with another. Its use gets awkward, however, when all we need to do is replace the last part of the array with something different. A quick look at the syntax reveals where it starts to get inconvenient—the replacement
parameter is preceded by the length
parameter, as shown here:
Get hands-on with 1200+ tech skills courses.