[英]How to merge two arrays into one in CodeIgniter?
This is my config file which contains form attributes in CodeIgniter. 这是我的配置文件,其中包含CodeIgniter中的表单属性。
$config['reg_attribute'] = array(
'form' => array(
'id' => 'reg-form',
'class' => 'form-horizontal',
'role' => 'form'
),
'name' => array(
'id'=>'reg-name',
'class' => 'form-control',
'name'=>'name',
'placeholder' => 'Enter name',
'value'=>set_value('name')
),
'gender' => array(
'id'=>'reg-reg',
'class' => 'form-control',
'name'=>'gender',
'value'=>set_value('gender')
),
'contact_no' => array(
'id'=>'reg-reg',
'class' => 'form-control',
'name'=>'contact_no',
'placeholder' => 'Enter Phone number',
'value'=>set_value('contact_no')
),
'email'=> array(
'id'=>'reg-email',
'class' => 'form-control',
'name'=>'email',
'placeholder' => 'Enter Email',
'value'=>set_value('email')
),
'password' =>array(
'id'=>'reg-password',
'class' => 'form-control',
'name'=>'password',
'placeholder'=>'Enter Password',
'value'=>set_value('password')
),
'confirm_password' =>array(
'id'=>'reg-password',
'class' => 'form-control',
'name'=>'confirm_password',
'placeholder'=>'Enter Confirm Password',
'value'=>set_value('confirm_password')
),
'submit' =>array(
'id' => 'btn-login',
'class' => 'btn btn-success',
'name' => 'submit',
'value' => 'Register'
)
);
Here I'm loading the form attributes from config and storing it into an array $data["reg_attrib"]
这里我从config加载表单属性并将其存储到数组
$data["reg_attrib"]
$this->config->load('reg_rules');
$data["reg_attrib"] = $this->config->item("reg_attribute");
I have an another array which is $add_form
我有另一个
$add_form
数组
$add_form = array(
'action' => base_url('admin/user/insert'),
'title' => 'Add User',
);
Now I want to merge both the array's into a single array and send it to view ie to $add_attributes
. 现在我想将数组合并到一个数组中并将其发送到view,即
$add_attributes
。
$this->admin_layout->view('admin/add_user',$add_attributes);
Simply merge them with array_merge()
. 只需将它们与
array_merge()
合并即可。 Try this - 尝试这个 -
$add_attributes = array_merge($data["reg_attrib"], $add_form);
use array_merge()
function like 使用
array_merge()
函数
$merged_arr = array_merge($arr1,$arr2);
in your case it will be same as @BOSE suggested: 在你的情况下,它将与@BOSE建议相同:
$add_attributes = array_merge($data["reg_attrib"], $add_form);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.