php - permutation/generate combination prefix and suffix -


i have array of prefixes, array of base words , array of suffixes. see every combination can made.

example:

   prefixes: 1 2     words: hello test     suffixes: _x _y     results:  1hello_x  1hello_y  1hello    1test_x   1test_y   1test     1_x       1_y       1         2hello_x  2hello_y 2hello   2test_x  2test_y  2test    2_x      2_y      2        hello_x  hello_y  hello    test_x   test_y   test     _x       _y       y 

how can this?

edit: responses, going through solutions seems if there no prefixes, fail combination. should still go through base words , suffixes, without prefixes.

function combineall ($prefixes, $words, $suffixes) {   $combinations = array ();   foreach ($prefixes $prefix)   {     foreach ($words $word)     {       foreach ($suffixes $suffix)       {          $combinations[] = $prefix.$word.$suffix;       }     }   }   return $combinations; } 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -