PHP Convert string into array -
how convert string $string = 'array(array("a"=>"content"))'; (<-- string) array this:
array(1) { [0]=> array(1) { ["a"]=> string(7) "content" } } i going build function run serialize online:
input: $string = 'array(array(1))'; echo serialize($string);
result: a:1:{i:0;a:1:{i:0;i:1;}} not s:16:"array(array(1)))";
you call: $returnvalue = serialize('array(array(1))');
you /could/ use eval():
$string = 'array(array("a"=>"content"))'; eval("\$array = $string;"); print_r($array); output:
array ( [0] => array ( [a] => content ) ) but if you're accepting user inputs, should not use eval().
also, consider using json_encode() / json_decode() instead.
alternatively, store arrays in strings, use serialize , unserialize.
Comments
Post a Comment