所以我有一个数组,其中包含我需要加入另一个表的信息,对于每个键,我需要将它加入到 form_lookup 表中,然后我需要用我从数据库中检索到的数据替换数组的键。我的问题是最快和最好的方法是什么?我已经有了 form_information 数组
试图:
$form_titles =array();
foreach (form_information[0] as $key => $value) {
$this->db->select('NAME');
$this->db->from('form_lookup');
$this->db->where('CODE', $key );
$query = $this->db->get();
}
$form_names = $query->result_array();
$form_titles[] = $campus_forms;
现在我需要用form_titles数组中的键替换form_information中的键。
$final_array = array_replace($form_information, $replacements);
form_information##(初始数组)
[0] => Array
(
[FIELD_1] => information
[FIELD_2] => information
[FIELD_3] => information
[FIELD_4] => information
[FIELD_5] => information
...
)
表form_lookup
CODE_ID | NAME
--------------
FIELD_1 | Name
--------------
FIELD_2 | ID
-------------
FIELD_3 | Contact
--------------
FIELD_4 | Lookup
-------------
FIELD_5 | Campus
(最终数组)
[0] => Array
(
[Name] => information
[ID] => information
[Contact] => information
[Lookup] => information
[Campus] => information
...
)