I get from the database here is a string value:
'[0,11]' How to convert it to php array now?
If directly breaking in, then:
$str = '[0,11]'; $result = explode(',', trim($str, "][")); trim - cuts the brackets, since The second parameter is a function that accepts a list of characters to be deleted.
explode - breaks the string on the comma delimiter into an array of numbers.
Another option:
$str = '[0,11]'; $result = json_decode($str); http://sandbox.onlinephpfunctions.com/code/d7d6b0b933dd591cee2faeb98ad6e88086ce8447
And it would be more correct, kmk, to immediately receive from the database the correct data set
Source: https://ru.stackoverflow.com/questions/759741/
All Articles