PermutationUtility

Class with helper functions for permuting items.

Table of Contents

Methods

meltArrayItems()  : array
Combines arbitrary items of multiple arrays as cross-product into flat items.
meltStringItems()  : array
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[] $payload[, array $previousResult = [] ]) : array

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[]

Distinct items that should be melted

$previousResult : array = []

Previous item results

Return values
array

meltStringItems()

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

public static meltStringItems(array[] $payload[, string $previousResult = '' ]) : array

Example:

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

Distinct array that should be melted

$previousResult : string = ''

Previous item results

Return values
array

asString()

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

nextItems()

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

Search results