-4

I have some data like: oil dispenser, oil container, oil spray bottle, oil Bottle And I want it to become: ["oil dispenser", "oil container", "oil spray bottle", "oil Bottle"] How can I convert a string into an array?

3
  • Does this answer your question? Array to String PHP? Commented Dec 4, 2019 at 7:58
  • Does this answer your question? Split PHP Variable in to array Commented Dec 4, 2019 at 7:59
  • @Nick yep that's implode() Commented Dec 4, 2019 at 8:26

1 Answer 1

1

Try this:

Solution

$string = 'oil dispenser, oil container, oil spray bottle, oil Bottle';

$array = array_map('trim', explode(',', $string));

var_dump($array);

Output

array(4) {
  [0]=>
  string(13) "oil dispenser"
  [1]=>
  string(13) "oil container"
  [2]=>
  string(16) "oil spray bottle"
  [3]=>
  string(10) "oil Bottle"
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.