我可能误解了文档,但是当我编码时
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
)
我试图让它获取给定的任何字符串的前两个单词并将它们放入一个数组中。
谢谢
你需要数组切片 https://www.php.net/manual/en/function.array-slice.php.
$result = array_slice(explode(" ","here's a sentence", 3), 0, 2);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)