array_slice
Extracts a slice of an array based on offset and length parameters without modifying the original array.
Parameters
main.php
Return Values
array
Returns the extracted portion of the array
On success:Array containing the specified slice of elements
On failure:Empty array if offset is larger than array size
Notes
- Does not modify the original array - returns a new array
- Negative offset starts from the end of the array
- Negative length stops that many elements before the end
- Use preserve_keys=true to maintain original array keys
Changelog
- 8.0.0: length is now nullable
Related Functions
substr
StringReturns a portion of a string specified by start and length parameters.
substringextractslice
array_column
ArrayReturns the values from a single column in a multi-dimensional array or array of objects.
extractcolumndatabase
array_keys
ArrayReturns all keys or a subset of keys from an array, optionally filtered by value.
keysextractstructure