gpt4 book ai didi

php - 如何在 CodeIgniter 中将两个数组合并为一个?

转载 作者:行者123 更新时间:2023-12-02 04:21:54 24 4
gpt4 key购买 nike

这是我的配置文件,其中包含 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'

)
);

这里我从配置加载表单属性并将其存储到数组 $data["reg_attrib"]

$this->config->load('reg_rules');
$data["reg_attrib"] = $this->config->item("reg_attribute");

我有另一个数组,它是 $add_form

 $add_form = array(
'action' => base_url('admin/user/insert'),
'title' => 'Add User',
);

现在我想将两个数组合并为一个数组并将其发送到查看,即发送到 $add_attributes

$this->admin_layout->view('admin/add_user',$add_attributes);

最佳答案

只需使用array_merge()将它们合并即可。试试这个 -

$add_attributes = array_merge($data["reg_attrib"], $add_form);

关于php - 如何在 CodeIgniter 中将两个数组合并为一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29790648/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com