如何将大数组切成小数组

时间:2013-06-19 04:11:26

标签: php arrays string

如何将任意长度的句子切成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答案。

提前感谢解决问题的人。

1 个答案:

答案 0 :(得分:7)

请参阅array_chunk()

$words = str_word_count($sentence, 1);
$chunks = array_chunk($words, 5);