1

I have a string like below

 "\$tempArray['acct'][0]".$det["PATH"]

$det["PATH"] is an dynamically generated in each iteration. something like this "['e2']['2']['e2']['0']['e2']['0']"

I want an array to be defined like this

$tempArray['acct'][0]['e2']['2']['e2']['0']['e2']['0'] = array ();

Since $det["path"] changes in every iteration . I need this array to be created for in each iteration with the name

I have tried the below code . But it creates and array with $tmpArray. not like this $tempArray['acct'][0]['e2']['2']['e2']['0']['e2']['0']

 if(!is_array("\$tempArray['acct'][0]".$det["PATH"])){
   $tArray = "\$tempArray['acct'][0]".$det["PATH"];
   var_dump($tArray );
   $tArray = array();                          
0

1 Answer 1

1

The insecure way to do this is eval:

eval("\$tempArray['acct'][0]".$det["PATH"]." = array();");

The better way is to use the path as the key:

$tempArray['acct'][0][$det["PATH"]] = array();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.