我有一个场景,我认为需要某种递归迭代,但我不确定,而且不是递归编码专家,我正在画一个空白。
这是场景:
我有这样一句话:
[He|She] would [like|love|hate] to [Play Golf|Play Tennis|Play Baseball] Today.
我希望 PHP 解析该短语([] 括号内的每个部分表示该单词或短语的可能变体,每个可能性由 | 管道分隔),并生成所有变体,例如,上面将返回:
He would like to Play Golf Today.
He would like to Play Tennis Today.
He would like to Play Baseball Today.
He would love to Play Golf Today.
He would love to Play Tennis Today.
He would love to Play Baseball Today.
He would hate to Play Golf Today.
He would hate to Play Tennis Today.
He would hate to Play Baseball Today.
She would like to Play Golf Today.
She would like to Play Tennis Today.
She would like to Play Baseball Today.
She would love to Play Golf Today.
She would love to Play Tennis Today.
She would love to Play Baseball Today.
She would hate to Play Golf Today.
She would hate to Play Tennis Today.
She would hate to Play Baseball Today.
我试图弄清楚如何编写 PHP 代码来获取输入的短语,并返回所有可能的句子。