Say I have a text string: {a|b|c|d} {a|b|c|d} {a|b|c|d} {a|b|c|d}.
And simple PHP function to shuffle the text:
function fb_filter_shuffle($string)
{
if(empty($string))
{
return NULL;
}
return preg_replace_callback('/\{.*?\}/i', function($m)
{
$options = explode('|', mb_substr($m[0], 1, -1));
shuffle($options);
return current($options);
}, $string);
}
I need to get all possible variations of the output. But how? the only option I came up so far, was to run the code nnn times and pick the unique options. Any more efficient suggestions?
30 seconds with Google and look what I came up with 😉
http://docstore.mik.ua/orelly/webprog/pcook/ch04_25.htm