从数组生成单词堆栈
我正在尝试用 PHP 做一个简单的词云练习,但没有什么变化。我已经完成了其他所有操作,但我不知道如何进行组合单词的循环。
这是一个示例,可以让您更容易理解我想要做什么:
我有这样的数组:
$arr = array('换行','缩进','代码','问题','更喜欢','我们','编程')
现在我正在尝试执行一个函数,该函数开始遍历该数组并给出我这样的数组:
数组( [0] => '换行' [1] => '换行缩进' [2] => '换行缩进代码' )
数组( [0] => ‘缩进’ [1] => '缩进代码' [2] => '缩进代码问题' )
所以基本上它会逐字遍历原始单词数组,并生成这些包含 1 到 5 个下一个单词的小数组。
I'm trying to do a simple word cloud exercise in PHP but with little twist. I have everything else done but I can't figure out how to do a loop that combines the words.
Here's example that will make it little bit easier to understand what I'm trying to do:
I have array like this:
$arr = array('linebreak','indent','code','question','prefer','we','programming')
Now I'm trying to do a function that starts going thru that array and gives me arrays like these:
Array(
[0] => 'linebreak'
[1] => 'linebreak indent'
[2] => 'linebreak indent code'
)Array(
[0] => 'indent'
[1] => 'indent code'
[2] => 'indent code question'
)
So basically it goes thru the original words array word by word and makes these little arrays that has 1 to 5 next words combined.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
递归可能是一条出路。我还没有详尽地检查以下语法。
Recursion may be the way to go. I haven't exhaustively checked the below for syntax.