生成单词组合
例如,这是我的文本:
$str = 'buy new microsoft windows';
我用数组分解文本和列表:
Array
(
[0] => buy
[1] => new
[2] => microsoft
[3] => windows
)
我想在数组中生成类似这样的单词:
buy new
buy new windows
buy microsoft
buy microsoft windows
buy windows
new microsoft
new microsoft windows
new windows
microsoft windows
我尝试使用 foreach 和 rand 但无法生成如图所示的内容。有没有机会按照我的要求生成?
For example this is my text :
$str = 'buy new microsoft windows';
I explode text and list with array :
Array
(
[0] => buy
[1] => new
[2] => microsoft
[3] => windows
)
I want to generate words in array to something like this:
buy new
buy new windows
buy microsoft
buy microsoft windows
buy windows
new microsoft
new microsoft windows
new windows
microsoft windows
I tried with foreach and rand but I couldn't generate like showed. Is there any chance to generate just like my request?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你可以看看这个 PEAR 包
用法示例:
输出将是:
You can have a look at this PEAR PACKAGE
Example usage:
The output will be:
这会给你一个随机“句子”。根据需要重复。
This gives you one random "sentence". Repeat as necessary.
从 php.net shuffle doc 找到
,结果将是,
Found from php.net shuffle doc
and the results will be,
来源: http://docstore.mik .ua/orelly/webprog/pcook/ch04_26.htm#phpckbk-CHP-4-EX-6
还检查该站点
示例上的下一个示例:
pc_permute(explode('','购买新的微软Windows'));
source: http://docstore.mik.ua/orelly/webprog/pcook/ch04_26.htm#phpckbk-CHP-4-EX-6
also check next example on that site
example:
pc_permute( explode( ' ', 'buy new microsoft windows' ) );
对于所有可能的组合,我改进了 @SujitAgarwal 答案:
下载 Math_Combinatoeics 。
输出 :
For All Possible Combinations I improved @SujitAgarwal Answer :
Download Math_Combinatoeics.
Output :