So My problem is:
- I want to create nested array from string as reference.
- My String is
"res[0]['links'][0]" - So I want to create array
$res['0']['links']['0']
I tried:
$result = "res[0]['links'][0]";
$$result = array("id"=>'1',"class"=>'3');
$result = "res[0]['links'][1]";
$$result = array("id"=>'3',"class"=>'9');
when print_r($res)
I see:
<b>Notice</b>: Undefined variable: res in <b>/home/fanbase/domains/fanbase.sportbase.pl/public_html/index.php</b> on line <b>45</b>
I need to see:
Array
(
[0] => Array
(
[links] => Array
(
[0] => Array
(
[id] => 1
[class] => 3
)
)
)
[1] => Array
(
[links] => Array
(
[0] => Array
(
[id] => 3
[class] => 9
)
)
)
)
Thanks for any help.
So you have a description of an array structure, and something to fill it with. That’s doable with something like:
Note how the array name itself is not part of the structure descriptor. But you could theoretically keep it. Instead call the
array_create()function with a$tmpvariable, and afterwardsextract()it to achieve the desired effect:Another lazy solution would be to use str_parse after a loop combining the array description with the data array as URL-encoded string.