Slice
in package
Represents a slice definition for selecting a range of elements.
Table of Contents
Methods
- __construct() : mixed
- Creates a new Slice instance with optional start, end, and step values.
- getEnd() : int|null
- Getter for the stop index of the normalized slice.
- getStart() : int|null
- Getter for the start index of the normalized slice.
- getStep() : int|null
- Getter for the step of the normalized slice.
- isSlice() : bool
- Checks if the provided value is a Slice instance or a valid slice string.
- isSliceArray() : bool
- Checks if the provided value is a valid slice array.
- isSliceString() : bool
- Checks if the provided value is a valid slice string.
- normalize() : NormalizedSlice
- Normalizes the slice parameters based on the container length.
- toSlice() : Slice
- Converts a slice string or Slice object into a Slice instance.
- toString() : string
- Returns the string representation of the Slice.
Methods
__construct()
Creates a new Slice instance with optional start, end, and step values.
public
__construct([int|null $start = null ][, int|null $end = null ][, int|null $step = null ]) : mixed
Parameters
- $start : int|null = null
-
The start index of the slice range.
- $end : int|null = null
-
The end index of the slice range.
- $step : int|null = null
-
The step size for selecting elements in the slice range.
getEnd()
Getter for the stop index of the normalized slice.
public
getEnd() : int|null
Return values
int|nullgetStart()
Getter for the start index of the normalized slice.
public
getStart() : int|null
Return values
int|nullgetStep()
Getter for the step of the normalized slice.
public
getStep() : int|null
Return values
int|nullisSlice()
Checks if the provided value is a Slice instance or a valid slice string.
public
static isSlice(mixed $s) : bool
Parameters
- $s : mixed
-
The value to check.
Return values
bool —True if the value is a Slice instance or a valid slice string, false otherwise.
isSliceArray()
Checks if the provided value is a valid slice array.
public
static isSliceArray(mixed $s) : bool
Parameters
- $s : mixed
-
The value to check.
Return values
bool —True if the value is a valid slice array, false otherwise.
isSliceString()
Checks if the provided value is a valid slice string.
public
static isSliceString(mixed $s) : bool
Parameters
- $s : mixed
-
The value to check.
Return values
bool —True if the value is a valid slice string, false otherwise.
normalize()
Normalizes the slice parameters based on the container length.
public
normalize(int $containerSize) : NormalizedSlice
Parameters
- $containerSize : int
-
The length of the container or array.
Tags
Return values
NormalizedSlice —The normalized slice parameters.
toSlice()
Converts a slice string or Slice object into a Slice instance.
public
static toSlice(string|Slice|array<string|int, int> $s) : Slice
Parameters
- $s : string|Slice|array<string|int, int>
-
The slice string/array or Slice object to convert.
Tags
Return values
Slice —The converted Slice instance.
toString()
Returns the string representation of the Slice.
public
toString() : string
Return values
string —The string representation of the Slice.