Reputation:
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!
Upvotes: 1
Views: 2861
Reputation: 227
You can try this code :
<?php
$string = "[2,1]";
$result = json_decode($string);
print_r($result);
?>
Output :
Array
(
[0] => 2
[1] => 1
)
Upvotes: 1
Reputation: 28564
It's a valid Json string. You can use json_decode to get the array.
json_decode("[2,1]");
Upvotes: 1