最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

显示字符串的可能组合

SEO心得admin55浏览0评论
本文介绍了显示字符串的可能组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图获取一个字符串并显示它的可能组合(在PHP中),但同时按每个单词的顺序说.例如:你好吗"将返回(一个数组)

I am trying to take a string and display the possible combinations of it (in PHP), but while saying in order of each word. For example: "how are you" would return (an array)

How are you How are are you how you are

我现在拥有的代码可以显示所有组合,但是我希望它能使它们保持顺序,而不是乱七八糟.任何人都有他们想分享的想法或摘要吗?谢谢

The code I have now displays all combinations but I am wanting it to keep them in order and not flip words. Any one have any ideas or snippets they care to share? Thanks

推荐答案

设置两个迭代器,并在它们之间打印所有内容.像这样:

Set two iterators and print everything between them. So something like this:

<? $str = "How are you"; $words = explode(" ",$str); $num_words = count($words); for ($i = 0; $i < $num_words; $i++) { for ($j = $i; $j < $num_words; $j++) { for ($k = $i; $k <= $j; $k++) { print $words[$k] . " "; } print "\n"; } } ?>

输出

How How are How are you are are you you
发布评论

评论列表(0)

  1. 暂无评论