I have a string which is stored like this:
["something", "someone", "anything", "anyone"]
Is there a direct function to convert something like this into an array? I tried eval() but it gave an unexpected end of file error.
For that example, you could do it with explode and a few str_replace calls:
$string = '["something", "someone", "anything", "anyone"]';
$string = str_replace("[","",$string);
$string = str_replace("]","",$string);
$string = str_replace('"',"",$string);
$array = explode(",",$string);
var_dump($array);
Also json_decode would work, as the comments stated:
$array = json_decode($string,true);
$string = '["something", "someone", "anything", "anyone"]';? if so, then just type cast it -var_dump((array) $string);$string = '["something", "someone", "anything", "anyone"]'; $array = json_decode($string); var_dump($array);alsojson_decode('["something", "someone", "anything", "anyone"]')