The spread operator in the arrays RFC has been implemented in PHP 7.4:
$ary = [3, 4, 5];
return [1, 2, ...$ary]; // same as [1, 2, 3, 4, 5]
Caveat: The unpacked array/Traversable can only have integer keys. For string keys array_merge()
is still required.
More Related Contents:
- How to search by key=>value in a multidimensional array in PHP
- php $_POST array empty upon form submission
- How to check if PHP array is associative or sequential?
- What is the best way to loop through this array in PHP?
- mysqli bind_param() expected to be a reference, value given
- What’s the best way to get the last element of an array without deleting it?
- Convert a comma-delimited string into array of integers?
- Convert array into csv
- Search for a key in an array, recursively
- Get the first N elements of an array?
- Get difference between associative rows of two 2-dimensional arrays
- php var_dump() vs print_r()
- PHP combine two associative arrays into one array
- using array_search for multi dimensional array
- PHP syntax for dereferencing function result
- How to find array / dictionary value using key?
- Flip associative array and store new values in subarrays to prevent losing duplicated values
- Sort a flat, associative array by numeric values, then by non-numeric keys
- Merge two indexed arrays of indexed arrays based on first column value
- Can’t concatenate 2 arrays in PHP
- Merge two numerically-keyed associative arrays and preserve the original keys
- laravel collection to array
- PHP Remove elements from associative array
- How do I move an array element with a known key to the end of an array in PHP?
- Alternate to array_column()
- Create PHP array from MySQL column
- Recreate original PHP array from print_r output [duplicate]
- How to convert an integer to an array in PHP?
- Save array in mysql database
- How do I check if array contains at least one empty value?