如何在codeigniter中将两个数组与键和值一起添加并插入表中?

时间:2017-05-03 09:40:46

标签: php mysql arrays codeigniter

我有两个数组。一个是手动创建的数组,另一个是发布数组。我想把钥匙和价值结合起来。下面是我的阵列。我希望这作为[1st_service] => 11,[2nd_service] => 12 ..等..并将其插入我的表格

    $services =Array([1st_service] => 
                     [2nd_service] => 
                     [3rd_service] => 
                     [4th_service] => )
    $servicecost = Array([0] => 11
                   [1] => 12
                   [2] => 13
                   [3] => 14)

1 个答案:

答案 0 :(得分:0)

希望这会帮助你。

<?php

ini_set('display_errors', 1);

$services = Array(
    "1st_service" => "",
    "2nd_service" => "",
    '3rd_service' => "",
    "4th_service" => "");

$servicecost = Array(
   0 => 11,
   1 => 12,
   2 => 13,
   3 => 14);
$keys=  array_map(function($value){
    return $value="name.".$value;
},array_keys($services));
print_r(array_combine($keys, $servicecost));

<强>输出:

Array
(
    [name.1st_service] => 11
    [name.2nd_service] => 12
    [name.3rd_service] => 13
    [name.4th_service] => 14
)