1

I've saved some users ids in the database like this:

column user_ids: [2,1]

When I show column's value is "[2,1]"

How can I convert this to an array!

2 Answers 2

1

It's a valid Json string. You can use json_decode to get the array.

json_decode("[2,1]");

Sign up to request clarification or add additional context in comments.

Comments

1

You can try this code :

<?php
$string = "[2,1]";
$result = json_decode($string);
print_r($result);
?>

Output :

Array
(
    [0] => 2
    [1] => 1
)

Comments

Your Answer

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