How to convert string ["4"] to real array?

How do you guys get values stored as varchar in format like: ["4"] ? For some reason, when I do $article->category[0] it returns [ instead of 4 - probably because it looks at it as a string and [ is the 0th character. But how to make PHP think ["4"] is an array and to return 4 when asking for 0th item? Thanks in advance.
3 Replies
Wirkhof
Wirkhof4mo ago
I am writing a custom code in my logic, it has nothing to do with database in this case. But thanks anyway. I ended up with substr , explode and a loop with another substr. But perhaps there is some dedicated PHP function for such conversion.
Saade
Saade4mo ago
json_decode() ? you wrote "get values stored as varchar" which led me to think you're talking about a database column/ model attribute
Want results from more Discord servers?
Add your server
More Posts