I'm new to PHP and could not find a proper answer to this.
$whatever = "array('Test','Blah')";
echo $parsed[2]; //This will be "Blah"
I want to create a variable called $parsed
which contains $whatever
's value but as a valid array instead of a string.
I'm aware I can just create the array by removing the quotation marks around it like this:
$whatever = array('Test','Blah');
In the actual code I'm working on, though, this isn't a possibility. Also, in my actual code, the array is multidimensional, so something involving a character replacement would probably be impractical, however I'm not ruling it out if it's the best option.
So to sum it up, what's the best way to go about parsing a string as an array in PHP?
['Test','Blah']
. – vstm Aug 31 '12 at 9:49array
attached to it. Wasn't it some brilliant idea to rely uponvar_export
as a naive serializer - and couldn't it be overriden with, like, sane choices (serialize
,json_encode
)? – raina77ow Aug 31 '12 at 9:49