【问题标题】:how can I slice a string and append into a array如何对字符串进行切片并附加到数组中
【发布时间】:2023-04-03 23:00:01
【问题描述】:

我需要对一个字符串进行切片并追加一个数组,字符串是这样的:

"stringPartOne stringPartTwo stringPartThree"

我想要一个这样的数组:

['stringPartOne', 'stringPartTwo', 'stringPartThree']

考虑到元素的数量是动态的,如何将此字符串切片并附加到数组中

【问题讨论】:

标签: php arrays string


【解决方案1】:

要正式回答 - 使用explode

$str = "stringPartOne stringPartTwo stringPartThree";
$arr = explode(" ", $str);

【讨论】:

    猜你喜欢
    • 2020-12-31
    • 2012-11-20
    • 2011-12-03
    • 2021-03-12
    • 2012-07-13
    • 1970-01-01
    • 2014-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多