0

I have a string like this:

$str = '"list":["test 1","test 2"]';

How to make an array:

$arr['list'] = array('test 1','test 2');

?

1
  • missed quotes. Thanks. Commented Jul 27, 2013 at 6:34

1 Answer 1

3

Make it a valid JSON string and use json_decode function like this:

$str = '"list":["test 1","test 2"]';
$arr = json_decode('{' . $str . '}', true);
print_r($arr);

OUTPUT:

Array
(
    [list] => Array
        (
            [0] => test 1
            [1] => test 2
        )
)
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.