1

How do I convert '["1","2-1","3-1-1"]' into ["1","2-1","3-1-1"]?

So, a string into an array.

I've tried casting '["1","2-1","3-1-1"]' to an array, but that does not work.

1
  • Is a json_decode no option for you Commented Sep 22, 2020 at 10:50

1 Answer 1

4

Use json_decode:

$arr = json_decode($str);

$str = '["1","2-1","3-1-1"]';
$arr = json_decode($str);

var_dump($arr);

array(3) {
  [0]=>
  string(1) "1"
  [1]=>
  string(3) "2-1"
  [2]=>
  string(5) "3-1-1"
}
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.