我希望代码在php示例中通过2个单词得到2个单词:
stackoverflow the best site of asking
Run Code Online (Sandbox Code Playgroud)
结果:
2 words : stackoverflow the
2 words : best site
2 words : of asking
Run Code Online (Sandbox Code Playgroud)
$array_of_words = implode(' ',array_chunk(explode(' ',$text), 2));
print_r($array_of_words);
Run Code Online (Sandbox Code Playgroud)
这应该给你
0 => stackoverflow 1 =>最佳站点2 =>询问
将阵列分成大块大块.最后一个块可能包含小于size的元素
使用胶水串连接数组元素