-1

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

7
  • 2
    $arr = explode(" ", $str)? Commented Mar 4, 2019 at 16:51
  • Show your minimal reproducible example. Commented Mar 4, 2019 at 16:57
  • @jdv the question is very simple, if you need my Minimal, Complete, and Verifiable example probably can not help me, but thank you very much Commented Mar 4, 2019 at 17:12
  • 1
    Possible duplicate of Splitting a string and adding to array Commented Mar 4, 2019 at 17:19
  • @TheDev read How to Ask. A minimal reproducible example is almost always requested. The idea is you show what you have done first. Commented Mar 4, 2019 at 18:41

1 Answer 1

2

To make a formal answer - Use explode:

$str = "stringPartOne stringPartTwo stringPartThree";
$arr = explode(" ", $str);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.