【问题标题】:Make php explode split sentence into words使php将句子分解成单词
【发布时间】:2021-06-13 03:12:58
【问题描述】:

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

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

我最终...

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

有没有办法让爆炸返回...

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

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

谢谢

【问题讨论】:

标签: php explode


【解决方案1】:

你需要array_slice

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

【讨论】:

  • 谢谢。我会使用array_slice,但我认为我误解了explode,认为参数2应该给我我想要的结果。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-23
  • 2015-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-30
相关资源
最近更新 更多