Make php explode 分句成词

Make php explode split sentence into words

我可能误解了文档,但是当我编码时

explode(" ","here's a sentence",2 )

我最终得到...

Array
(
    [0] => here's
    [1] => a sentence with a few words in it
)

有没有办法让爆炸发生return...

Array
(
    [0] => here's
    [1] => a
)

我试图让它获取给定的任何字符串的前两个单词并将它们放入一个数组中。

谢谢

你需要array_slice.

$result = array_slice(explode(" ","here's a sentence", 3), 0, 2);