Contao Utils Bundle

ArrayUtil
in package

Table of Contents

Properties

$framework  : ContaoFramework
$container  : ContainerInterface

Methods

__construct()  : mixed
aasort()  : mixed
sort an array alphabetically by some key in the second layer (x => array(key1, key2, key3)).
arrayToObject()  : stdClass
Creates a stdClass from array.
filterByPrefixes()  : array<string|int, mixed>
Filter an Array by given prefixes.
flattenArray()  : array<string|int, mixed>
Flattens an multidimensional array to one dimension. Keys are not preserved.
getArrayRowByFieldValue()  : mixed
Returns a row of an multidimensional array by field value. Returns false, if no row found.
implodeRecursive()  : mixed
insertBeforeKey()  : mixed
Insert a new entry before an specific key in array.
insertInArrayByName()  : mixed
Insert a value into an existing array by key name.
removePrefix()  : array<string|int, mixed>
removeValue()  : bool
Removes a value in an array.

Properties

$framework

protected ContaoFramework $framework

$container

private ContainerInterface $container

Methods

__construct()

public __construct(ContainerInterface $container) : mixed
Parameters
$container : ContainerInterface

aasort()

sort an array alphabetically by some key in the second layer (x => array(key1, key2, key3)).

public aasort(array<string|int, mixed> &$array, mixed $key) : mixed
Parameters
$array : array<string|int, mixed>
$key : mixed

arrayToObject()

Creates a stdClass from array.

public arrayToObject(mixed $array) : stdClass
Parameters
$array : mixed
Return values
stdClass

filterByPrefixes()

Filter an Array by given prefixes.

public filterByPrefixes([array<string|int, mixed> $data = [] ][, array<string|int, mixed> $prefixes = [] ]) : array<string|int, mixed>
Parameters
$data : array<string|int, mixed> = []
$prefixes : array<string|int, mixed> = []
Return values
array<string|int, mixed>

the filtered array or $arrData if $prefix is empty

flattenArray()

Flattens an multidimensional array to one dimension. Keys are not preserved.

public flattenArray(array<string|int, mixed> $array) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>
Return values
array<string|int, mixed>

getArrayRowByFieldValue()

Returns a row of an multidimensional array by field value. Returns false, if no row found.

public getArrayRowByFieldValue(string|int $key, mixed $value, array<string|int, mixed> $haystack[, bool $strictType = false ]) : mixed
Parameters
$key : string|int

The array key (fieldname)

$value : mixed
$haystack : array<string|int, mixed>

a multidimensional array

$strictType : bool = false

Specifiy if type comparison should be strict (type-safe)

implodeRecursive()

public implodeRecursive(mixed $var[, mixed $binary = false ]) : mixed
Parameters
$var : mixed
$binary : mixed = false

insertBeforeKey()

Insert a new entry before an specific key in array.

public static insertBeforeKey(array<string|int, mixed> &$array, string $key, string $newKey, mixed $newValue) : mixed

Use Utils::insertBeforeKey() instead

If key not exist, the new entry is added to the end of the array. Array is passed as reference.

Usage example: contao config.php to make your hook entry run before another.

Parameters
$array : array<string|int, mixed>

Array the new entry should inserted to

$key : string

The key where the new entry should be added before

$newKey : string

The key of the entry that should be added

$newValue : mixed

The value of the entry that should be added

insertInArrayByName()

Insert a value into an existing array by key name.

public insertInArrayByName(array<string|int, mixed> &$current, string $key, mixed $value[, int $offset = 0 ][, bool $strict = false ]) : mixed

Use utils service instead

Parameters
$current : array<string|int, mixed>

The target array

$key : string

the existing target key in the array

$value : mixed

the new value to be inserted

$offset : int = 0

offset for inserting the new value

$strict : bool = false

use strict behavior for array search

Tags
codeCoverageIgnore

removePrefix()

public removePrefix(string $prefix, array<string|int, mixed> $array) : array<string|int, mixed>
Parameters
$prefix : string
$array : array<string|int, mixed>
Return values
array<string|int, mixed>

removeValue()

Removes a value in an array.

public removeValue(mixed $value, array<string|int, mixed> &$array) : bool

Use Utils service instead

Parameters
$value : mixed
$array : array<string|int, mixed>
Tags
codeCoverageIgnore
Return values
bool

Returns true if the value has been found and removed, false in other cases


        
On this page

Search results