php - Using an array value to retrieve from another array -


i have created array, 1 of intended string used php display field record retrieved sqlite3.

my problem ... doesn't.

the array defined, "1" being first database field, , "2" second database field:

edit : have re-defined problem script can see whole thing:

//if have array (simulating record retrieved database): $record = array(     name => 'joe',     comments => 'good bloke',     );  //then define array reference it: $fields = array(      1 => array(     'db_index' => 'name',     'db_type' => 'text',     'display' => '$record["name"]',     'form_label' => 'name',     ),     2 => array(     'db_index' => 'comments',     'db_type' => 'text',     'display' => '$record["comments"]',     'form_label' => 'comments',     ),   );    //if use lines: print "expected output:\n"; print " name = " . $record["name"] ."\n"; print " comments = " . $record["comments"] ."\n";  //i display results $record array correctly. //however if try & use fields array like: print "output using array values\n"; foreach($globals["fields"] $field)     {         $label = $field['form_label'];         $it = $field['display'];             $line = "\"$label = \" . $it .\"\n\"";         print $line;     } 

output:

expected output:  name = joe  comments = bloke output using array values:  name = $record["name"]   comments = $record["comments"]  

don't call variable string. concatenate :

foreach($globals["fields"] $field){     $label = $field['form_label'];     $it = $field['display'];      eval("$it = ".$it);     $line = $label." = ".$it."\n";     print $line; } 

well, how looks ?


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -