简体   繁体   English

我如何切片字符串并追加到数组中

[英]how can I slice a string and append into a array

I need slice a string and append intro a array, the string is like this: 我需要切片一个字符串并追加一个数组的介绍,字符串是这样的:

"stringPartOne stringPartTwo stringPartThree"

I want to have a array like this: 我想要一个像这样的数组:

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

How can I slice this string and append into a array considering that the number of elements is dynamic 考虑到元素数量是动态的,我该如何对该字符串进行切片并追加到数组中

To make a formal answer - Use explode : 做出正式答案-使用explode

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM