trait ArrayConversionsPart

Text methods for array/ArrayObject conversions

Methods

chunk(int $splitLength = 1)

Convert the string to an array

static Text
join(array $pieces, string $glue = '', string|null $encoding = null)

Join array elements with a string

split(string $delimiter, int $limit = PHP_INT_MAX)

Splits the string by string

Details

at line 96
ArrayObject chunk(int $splitLength = 1)

Convert the string to an array

Parameters

int $splitLength Maximum length of the chunk.

Return Value

ArrayObject If the optional splitLength parameter is specified, the returned array will be broken down into chunks with each being splitLength in length, otherwise each chunk will be one character in length. If the split_length length exceeds the length of string, the entire string is returned as the first (and only) array element.

Exceptions

InvalidArgumentException If splitLength is less than 1.

at line 69
static Text join(array $pieces, string $glue = '', string|null $encoding = null)

Join array elements with a string

Parameters

array $pieces The array of strings to join.
string $glue Defaults to an empty string.
string|null $encoding the desired encoding

Return Value

Text Returns a string containing a string representation of all the array elements in the same order, with the glue string between each element.

at line 48
ArrayObject split(string $delimiter, int $limit = PHP_INT_MAX)

Splits the string by string

Parameters

string $delimiter The boundary string.
int $limit If limit is set and positive, the returned array will contain a maximum of limit elements with the last element containing the rest of string.

    If the limit parameter is negative, all components except the last
    -limit are returned.

    If the limit parameter is zero, then this is treated as 1.

Return Value

ArrayObject Returns an array of strings created by splitting the string parameter on boundaries formed by the delimiter.

   If delimiter contains a value that is not contained in string and a negative limit is used,
   then an empty array will be returned, otherwise an array containing string will be returned.

Exceptions

InvalidArgumentException If the delimiter is an empty string.