Documentation

NormalizedSlice extends Slice
in package
implements Countable, IteratorAggregate

Represents a normalized slice definition with start, end, and step values.

Tags
implements

\IteratorAggregate<int, int>

Table of Contents

Interfaces

Countable
IteratorAggregate

Methods

__construct()  : mixed
Creates a new Slice instance with optional start, end, and step values.
convertIndex()  : int
Converts the provided index to the actual index based on the normalized slice parameters.
count()  : int
Return size of the slice range.
getEnd()  : int|null
Getter for the stop index of the normalized slice.
getIterator()  : Generator<int, int>
Return iterator to iterate slice range.
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.

convertIndex()

Converts the provided index to the actual index based on the normalized slice parameters.

public convertIndex(int $i) : int
Parameters
$i : int

The index to convert.

Return values
int

The converted index value.

count()

Return size of the slice range.

public count() : int
Return values
int

Size of the slice range.

getEnd()

Getter for the stop index of the normalized slice.

public getEnd() : int|null
Return values
int|null

getIterator()

Return iterator to iterate slice range.

public getIterator() : Generator<int, int>
Return values
Generator<int, int>

getStart()

Getter for the start index of the normalized slice.

public getStart() : int|null
Return values
int|null

getStep()

Getter for the step of the normalized slice.

public getStep() : int|null
Return values
int|null

isSlice()

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
throws
IndexError

if the step value is 0.

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
throws
ValueError

if the slice representation is invalid.

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.


        
On this page

Search results