如何将任意长度的句子切成5个字的数组?如何将一个大数组切片成较小的数组
换句话说:
$Dummy = "Here is a long sentence, but what I need to make out of this sentence
is that it should be chunked off to smaller arrays with 5 words each."
我想在PHP的答案。
预先感谢解决它的人。
如何将任意长度的句子切成5个字的数组?如何将一个大数组切片成较小的数组
换句话说:
$Dummy = "Here is a long sentence, but what I need to make out of this sentence
is that it should be chunked off to smaller arrays with 5 words each."
我想在PHP的答案。
预先感谢解决它的人。
请参阅array_chunk()
。
$words = str_word_count($sentence, 1);
$chunks = array_chunk($words, 5);
请发表您的代码到目前为止,并解释什么是行不通的。 – elclanrs
不是很确定的要求,但尝试'爆炸()' – swapnesh
可能的重复:[我如何只获得一个确定数量的字从字符串在PHP?](http://stackoverflow.com/ q/1112946/367456) - 和其他许多人。请使用搜索。 – hakre