1

I get from my database a string that looks like:

    $result = "[02,04,05,09,21]";

And that works as a string all together, is that possible that I make it an array that would like: array[0] = 02 , array[1] = 04, and so go on?

2 Answers 2

2

Yes this is possible:

$result = "[02,04,05,09,21]";
$result = substr($result, 1, -1);
$arr = explode(",", $result);
Sign up to request clarification or add additional context in comments.

3 Comments

That just worked perfectly ! Thank you very much ! By the way, if you know anyway to do the reverse I would be very thankful.
Glad to help. The reverse is just $result = "[" . implode(",", $arr) . "]"
Thank you very much again !
0

Trim the bracket notations from the string and simply explode it with comma

$result = "[02,04,05,09,21]";
$result = rtrim(ltrim($result, '['), ']');
$array  = explode(',', $result);

echo '<pre>';
print_r($array);

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.