fork download
  1. <?php
  2. header('Content-Type: text/plain; charset="utf-8"');
  3.  
  4. function createCombinations(array $input)
  5. {
  6. $head = array_shift($input);
  7. $tail = count($input) > 1 ? createCombinations($input) : array_shift($input);
  8.  
  9. $combinations = [];
  10. foreach ($head as $left) {
  11. foreach ($tail as $right) {
  12. $combinations[] = array_merge([$left], (array) $right);
  13. }
  14. }
  15.  
  16. return $combinations;
  17. }
  18.  
  19. $element = [
  20. 'vehical' => ['vehicle', 'car'],
  21. 'recovary' => ['recovery', 'recover', 'revary'],
  22. 'cubs' => ['cabs'],
  23. ];
  24.  
  25. $sentence = 'i want to recovary my vehical from the cubs';
  26. $from = array_keys($element);
  27.  
  28. foreach (createCombinations($element) as $to) {
  29. echo str_replace($from, $to, $sentence), "\n";
  30. }
Success #stdin #stdout 0.02s 52480KB
stdin
Standard input is empty
stdout
i want to recovery my vehicle from the cabs
i want to recover my vehicle from the cabs
i want to revary my vehicle from the cabs
i want to recovery my car from the cabs
i want to recover my car from the cabs
i want to revary my car from the cabs