Index
-
\com\setasign\SetaFramework
-
Helper
- ArrayHelper
- ConsoleHelper
- CsrfProtection
- CsrfProtectionException
- DataWrapper
- DatabaseCleaner
- Debugging
- FilesystemHelper
- FunctionWrapper
- JsonHelper
- Logger
- LoggerHelper
- MathHelper
- ObserverClosure
- OutputBufferHelper
- ParameterSanitizer
- PregMatchAllMatchesIterator
- RateLimiter
- ReturnValueClosure
- StringHelper
- SwiftMailerHelper
- UnexpectedOutputException
- UnserializableClosure
-
Helper
com\setasign\SetaFramework\Helper
ArrayHelper Class ArrayHelper
File: /SetaFramework/src/Helper/ArrayHelper.php
Class hierarchy
Summary
Static Methods
distribute()
callable $callback,
int $expectedResults = 2,
bool $preserveKey = false
Distribute an array by a callback into x-groups (x = $expectedResults).
The callback must have the following signature:
function($value, $key): int (The returned integer must be within 0 and ($expectedResult - 1))
Parameters
- $array : array
- $callback : callable
function($value, $key): int- $expectedResults : int
Defines into how many groups you want to distribute the array.
- $preserveKey : bool
If true the original key will be kept otherwise the key will be lost and forgotten.
ensureArray()
Ensures that the value is an array.
If the value isn't an array it will be packed into an array.
Parameters
- $value : mixed
ensureTravesable()
iterable $default = array ( )
Ensures that the value is travesable.
If the value isn't travesable $default is returned.
Parameters
- $value : mixed
- $default : iterable
first()
Returns the first item of an array
Parameters
- $array : array
- $default : mixed
Will be returned if $array is empty
groupBy()
callable $groupBy,
bool $errorOnDuplicate = true
Parameters
- $array : array
- $groupBy : callable
- $errorOnDuplicate : bool
last()
Returns the last item of an array
Parameters
- $array : array
- $default : mixed
Will be returned if $array is empty
naturalLanguageImplode()
string $lastGlue,
array $pieces
Parameters
- $glue : string
- $lastGlue : string
- $pieces : array
prepend()
Push an item onto the beginning of an array
Parameters
- $array : array
- $value : mixed
- $key : ?mixed
pull()
Pulls an item out of an array
Parameters
- $array : array
- $key : mixed
- $default : mixed
Will be returned if the item doesn't exist
pushWithKey()
Simple helper method to insert a value into an array
Parameters
- $array : array
- $key : mixed
- $value : mixed
random()
?int $amount = null,
bool $preserveKeys = false
Get one or a specified number of random values from an array.
Parameters
- $array : array
- $amount : ?int
- $preserveKeys : bool
Exceptions
Throws \InvalidArgumentException
striInArray()
Checks whether the string is in the array (case-insensitive).
Parameters
- $string : string
- $array : array
