Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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]"
"[2,1]"
How can I convert this to an array!
It's a valid Json string. You can use json_decode to get the array.
json_decode("[2,1]");
Add a comment
You can try this code :
<?php $string = "[2,1]"; $result = json_decode($string); print_r($result); ?>
Output :
Array ( [0] => 2 [1] => 1 )
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.