php - 用2个单词得到2个单词

use*_*313 -1 php

我希望代码在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)

MyS*_*eam 5

$array_of_words = implode(' ',array_chunk(explode(' ',$text), 2));
print_r($array_of_words);
Run Code Online (Sandbox Code Playgroud)

这应该给你

0 => stackoverflow 1 =>最佳站点2 =>询问

  • array_chunk()

    将阵列分成大块大块.最后一个块可能包含小于size的元素

  • 爆()

    使用胶水串连接数组元素