I was looking for in Stack some solution to convert a string variable to an Array. The String variable contents this:
$myvar = 'array("a" => array("b1" => 1, "b2" => "something"), "c" => array("d1" => 1))';
I want to convert as:
$myarray = array(
"a" => array (
"b1" => 1,
"b2" => "something"
),
"c" => array("d1" => 1)
);
I was using json_decode
after to convert my huge string to json, I used implode too ...
Using eval, I recieve next error:
Parse error: syntax error, unexpected '<' in tabletocreate.php(51) : eval()'d code on line 1
I used print_r($myvar);
The idea it is I have an model inside a file model.php it is only a dictionary, I read this file inside a string and after to convert again an array, I do it because I need to generate a new database from this data, and I have the model for each catalog I need products, offer, ... obiously each model will be different but with the same structure of array, I wrote in the example
SOLUTION
faintsignal resolved the solution in my case: eval("\$myarray = " . $myvar . ';');