PermutationUtility

Class with helper functions for permuting items.

Table of Contents

Methods

meltArrayItems()  : array<string|int, mixed>
Combines arbitrary items of multiple arrays as cross-product into flat items.
meltStringItems()  : array<string|int, mixed>
Combines string items of multiple arrays as cross-product into flat items.
asString()  : string
nextItems()  : iterable<string|int, mixed>

Methods

meltArrayItems()

Combines arbitrary items of multiple arrays as cross-product into flat items.

public static meltArrayItems(array<string|int, array<string|int, mixed>> $payload[, array<string|int, mixed> $previousResult = [] ]) : array<string|int, mixed>

Example:

  • meltArrayItems(['a','b'], ['c','e'], ['f','g'])
  • results into ['a', 'c', 'e'], ['a', 'c', 'f'], ['a', 'd', 'e'], ['a', 'd', 'f'], ['b', 'c', 'e'], ['b', 'c', 'f'], ['b', 'd', 'e'], ['b', 'd', 'f'],
Parameters
$payload : array<string|int, array<string|int, mixed>>

Distinct items that should be melted

$previousResult : array<string|int, mixed> = []

Previous item results

Return values
array<string|int, mixed>

meltStringItems()

Combines string items of multiple arrays as cross-product into flat items.

public static meltStringItems(array<string|int, array<string|int, mixed>> $payload[, string $previousResult = '' ]) : array<string|int, mixed>

Example:

  • meltStringItems([['a', 'b'], ['c', 'd'], ['e', 'f']])
  • results into ['ace', 'acf', 'ade', 'adf', 'bce', 'bcf', 'bde', 'bdf']
Parameters
$payload : array<string|int, array<string|int, mixed>>

Distinct array that should be melted

$previousResult : string = ''

Previous item results

Return values
array<string|int, mixed>

asString()

protected static asString(mixed $item) : string
Parameters
$item : mixed
Return values
string

nextItems()

protected static nextItems(array<string|int, mixed> &$payload) : iterable<string|int, mixed>
Parameters
$payload : array<string|int, mixed>
Return values
iterable<string|int, mixed>

        
On this page

Search results