Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将一个大数组分割成更小的数组_Php_Arrays_String - Fatal编程技术网

Php 如何将一个大数组分割成更小的数组

Php 如何将一个大数组分割成更小的数组,php,arrays,string,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 提前感谢解决问题的人 见 到目前为止,请发布您的代码,并解释哪些代码不起作用。对需求不是很确定,但请

如何将任意长度的句子切分为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

提前感谢解决问题的人


到目前为止,请发布您的代码,并解释哪些代码不起作用。对需求不是很确定,但请尝试使用
explode()
可能重复的:-和其他许多代码。请使用搜索。不希望
str\u word\u count
返回实际单词…好奇函数。除了str\u word\u count,您还可以使用explode函数$单词=爆炸(“,$句);例如,如果没有明确指定,StruthWordPyCube将不能使用数字字符,并将其视为定界符。@ MuHMMdHeDeTeWORD,<代码>开发()/代码>将为“双空间”留下空元素。一切都有它的局限性。还考虑<代码> ARAYYFILTER()/<代码>对不起,我是新来的,我对PHP了解不多。我可以看到切片部分,但现在我的问题是如何显示这些块,没有键,打印,也返回键。我只需要价值观。@SidSs:好吧,你没有问过这个问题,所以请不要抱怨没有得到这些未被问到的问题的回答。另外,我敢打赌,通过使用搜索,您可以更成功地找到答案:-想象一下,对于更简单的任务,您不是第一个对此感到好奇的人-无论PHP的技能水平如何。
$words = str_word_count($sentence, 1);
$chunks = array_chunk($words, 5);