CSArrayUtils
in package
[Short description of what the class is responsible for]
[More detailed description how the class performs the tasks, which it is responsible for]
Tags
Table of Contents
- compare() : bool
- Compares two arrays if they have any differences.
- getLastElement() : mixed
- Returns the last element of an array.
- inArray() : bool
- Wrapper helper method to php in_array function, with additional case insensitive parameter.
- insertAtPosition() : array<string|int, mixed>
- Inserts values to a specific position in a given array.
- isEmptyArray() : bool
- Verifies if the parameter is an array with no elements
- isNonEmptyArray() : bool
- Verifies if the parameter is an array with at least one element
- shortenStrings() : array<string|int, mixed>
- Shortens all string values in the provided array to the specified length. Values that are not strings, are not touched at all.
- split() : array<string|int, mixed>
- This method splits a large array into an array of lesser elements.
Methods
compare()
Compares two arrays if they have any differences.
public
static compare(array<string|int, mixed> $aFirstInput, array<string|int, mixed> $aSecondInput[, bool $bIndexCheck = false ]) : bool
Parameters
- $aFirstInput : array<string|int, mixed>
-
The first array, which should be compared
- $aSecondInput : array<string|int, mixed>
-
The second array, which should be compared
- $bIndexCheck : bool = false
-
Compares the two array with an additional index check.
Tags
Return values
bool —whether the compares are the same (true) or they have differences (false)
getLastElement()
Returns the last element of an array.
public
static getLastElement(array<string|int, mixed> $aInput) : mixed
Parameters
- $aInput : array<string|int, mixed>
-
The array with the elements.
Tags
Return values
mixed —value with the last element.
inArray()
Wrapper helper method to php in_array function, with additional case insensitive parameter.
public
static inArray(mixed $sNeedle, array<string|int, mixed> $aHaystack[, bool $bStrict = false ][, bool $bCaseInsensitive = false ]) : bool
Parameters
- $sNeedle : mixed
-
Value to search for
- $aHaystack : array<string|int, mixed>
-
Array to search
- $bStrict : bool = false
-
If set to true, then type will also be considered
- $bCaseInsensitive : bool = false
-
If set to true search will be case insensitive
Tags
Return values
bool —returns true if $sNeedle is found
insertAtPosition()
Inserts values to a specific position in a given array.
public
static insertAtPosition(array<string|int, mixed> $aValuesToInsert, array<string|int, mixed> $aTargetArray, int $iPosition[, bool $bPreserveKeys = false ]) : array<string|int, mixed>
Parameters
- $aValuesToInsert : array<string|int, mixed>
-
The values which should be inserted in the target array.
- $aTargetArray : array<string|int, mixed>
-
The target array which should be extended.
- $iPosition : int
-
The position to insert the values.
- $bPreserveKeys : bool = false
-
Whether the keys of the array should be preserved or not.
Tags
Return values
array<string|int, mixed> —with the inserted values
isEmptyArray()
Verifies if the parameter is an array with no elements
public
static isEmptyArray(mixed $mInput) : bool
Parameters
- $mInput : mixed
-
The variable to be tested
Tags
Return values
bool —TRUE if the parameter is an array with zero elements
isNonEmptyArray()
Verifies if the parameter is an array with at least one element
public
static isNonEmptyArray(mixed $mInput) : bool
Parameters
- $mInput : mixed
-
The variable to be tested
Tags
Return values
bool —TRUE if the parameter is an array with at least one element
shortenStrings()
Shortens all string values in the provided array to the specified length. Values that are not strings, are not touched at all.
public
static shortenStrings(array<string|int, mixed> $aArray[, int $iMaxLength = 1024 ]) : array<string|int, mixed>
Parameters
- $aArray : array<string|int, mixed>
-
The list of values to be shortened
- $iMaxLength : int = 1024
-
The max length of strings. If a string value is longer, it gets shortened to exactly this length.
Tags
Return values
array<string|int, mixed> —The new array with shortened string values.
split()
This method splits a large array into an array of lesser elements.
public
static split(array<string|int, mixed> $aInput[, int $iSteps = 100 ][, bool $bPreserveKeys = false ]) : array<string|int, mixed>
Parameters
- $aInput : array<string|int, mixed>
-
The array to split
- $iSteps : int = 100
-
The amount of elements in the array
- $bPreserveKeys : bool = false
-
Whether the keys should be preserved
Tags
Return values
array<string|int, mixed> —in array with the given step length.
