Advertisement
yhoezt_27

Untitled

Nov 20th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. function getCombinations($array) {
  2.  
  3. //initalize array
  4. $results = [[]];
  5.  
  6. //get all combinations
  7. foreach ($array as $k => $element) {
  8. foreach ($results as $combination){
  9. $results[] = $combination + [$k => $element];}
  10. }
  11.  
  12. //return filtered array
  13. return array_values(array_filter($results));
  14.  
  15. }
  16.  
  17. function prima($str,$haystack){
  18. if ($str != '')
  19. {
  20. if (count($haystack)>0)
  21. {
  22. $a = array();
  23. for($i=0; $i<count($haystack);$i++)
  24. {
  25. if (stripos($str, $haystack[$i]) !== false)
  26. {
  27. array_push($a,$haystack[$i]);
  28.  
  29. }
  30. //var_dump($haystack[$i]);
  31. }
  32. if (count($a) > 3)
  33. {
  34. $arr = getCombinations($a);
  35. for($j=0; $j<count($arr); $j++)
  36. {
  37. if (implode('',$arr[$j]) === $str)
  38. {
  39. print implode(';',$arr[$j]). "<br />";
  40. }
  41. }
  42.  
  43. }
  44. else print implode(';',$a). "<br />";
  45. }
  46. }
  47.  
  48. }
  49.  
  50. $regex = array('pro', 'gram', 'program', 'programmer', 'merit','it');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement