Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP文本洗牌和所有可能的选项_Php - Fatal编程技术网

PHP文本洗牌和所有可能的选项

PHP文本洗牌和所有可能的选项,php,Php,假设我有一个文本字符串:{a | b | c | d}{a | b | c | d}{a | b | c | d} 和简单的PHP函数来洗牌文本: function fb_filter_shuffle($string) { if(empty($string)) { return NULL; } return preg_replace_callback('/\{.*?\}/i', function($m) { $option

假设我有一个文本字符串:
{a | b | c | d}{a | b | c | d}{a | b | c | d}

和简单的PHP函数来洗牌文本:

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);
}

我需要得到输出的所有可能变化。但是怎么做呢?到目前为止,我唯一的选择是运行代码
nnn
次,然后选择唯一的选项。还有什么更有效的建议吗?

30秒谷歌,看看我想到了什么;)


您提供的链接不是一个好的解决方案。。。事实上,对于A,B,C,你得到的结果是:A,B,BA,C,CA,CB,CBA,它缺少AB,AC,ABC,BCA,CBA,不是吗?