You are here

function _fac_keys_sampling in Fast Autocomplete 7

Generates an array with all possible character combinations.

Parameters

array $chars: The characters to create all possible combinations for.

int $size: The size of the required combinations.

Return value

array An array of all possible character combinations with the given size.

1 call to _fac_keys_sampling()
_fac_create_search_array in ./fac.module
Creates an array with letter combinations to search for.

File

./fac.module, line 520
This file contains the main functions of the Fast Autocomplete module.

Code

function _fac_keys_sampling(array $chars, $size, $combinations = array()) {

  // If it's the first iteration, the first set of combinations is the same as
  // the set of characters.
  if (empty($combinations)) {
    $combinations = $chars;
  }

  // We're done if we're at size 1.
  if ($size == 1) {
    return $combinations;
  }

  // Initialise array to put new values in.
  $new_combinations = array();

  // Loop through existing combinations and character set to create strings.
  foreach ($combinations as $combination) {
    foreach ($chars as $char) {
      $new_combinations[] = $combination . $char;
    }
  }

  // Call same function again for the next iteration.
  return _fac_keys_sampling($chars, $size - 1, $new_combinations);
}