Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法使用多维数组获取结果_Php_Arrays_Multidimensional Array_Codeigniter 2 - Fatal编程技术网

Php 无法使用多维数组获取结果

Php 无法使用多维数组获取结果,php,arrays,multidimensional-array,codeigniter-2,Php,Arrays,Multidimensional Array,Codeigniter 2,这里给出的tool\u id分别是7和5,选择的quantity分别是3和2。当我选择7的tool\u id时,我需要将tool\u id的数量更改为3,当我选择tool\u idof5我需要将tool\u id的数量更改为2。需要根据所选id进行更改请帮助我解决问题 这是我的密码 $tool_id = array(7,5); //array of id $quantity = array(3,2);//array or qty $updateArray = array(); for($x =

这里给出的
tool\u id
分别是
7
5
,选择的
quantity
分别是
3
2
。当我选择
7
tool\u id
时,我需要将
tool\u id
数量更改为
3
,当我选择
tool\u id
of
5
我需要将
tool\u id
数量更改为
2
。需要根据所选id进行更改请帮助我解决问题 这是我的密码

$tool_id = array(7,5); //array of id
$quantity = array(3,2);//array or qty
$updateArray = array();
for($x = 0; $x < count($tool_id); $x++){
    $updateArray[] = array(
        'id'=>$tool_id[$x],
        'available' => $quantity[$x]
    );
}      
$this->db->update_batch('tbl_tools',$updateArray,'id');
}

这里有两个表,即
tbl\u工具
tbl\u工具使用
tbl_工具
如下所示

id  name            quantity    available   type        
5   cutting player     5          5        engineer     
6   reflectors         2          2        team     
7   spanner            8          8        engineer     
8   tester             4          4        team 
id  user_id     type      tool_id   quantity    available               start_date  end_date
201  26        engineer     7,5     3,2        8available,5available    2016-12-30  
tbl\u工具的使用

id  name            quantity    available   type        
5   cutting player     5          5        engineer     
6   reflectors         2          2        team     
7   spanner            8          8        engineer     
8   tester             4          4        team 
id  user_id     type      tool_id   quantity    available               start_date  end_date
201  26        engineer     7,5     3,2        8available,5available    2016-12-30  
在表
tbl\u tool\u use
中,选择的刀具id为7和5,选择的数量分别为3和2,同时将此数据插入到该表中,我的
tbl\u tools
表应如下减少

id  name            quantity    available   type        
5   cutting player     5          2        engineer     
6   reflectors         2          2        team     
7   spanner            8          3        engineer     
8   tester             4          4        team 
这是我使用该代码的概念,这是您的解决方案

    $tool_id = array(7,5); //array of id
    $quantity = array(3,2);//array or qty
    $arrayCombine = array_combine($tool_id, $quantity);
    // var_dump($arrayCombine);
    foreach ($arrayCombine as $key => $value) {
        $updateArray[] = array(
            'id'=>$key,
            'available' => $value
        );

    }
    $this->db->update_batch('tbl_tools',$updateArray,'id');

获取所提供工具id的
$t\u id
索引,然后使用该索引更改数量数组,就像我在这里所做的一样。任何人都有任何想法。尝试一下这个想法我已经尝试了很多,如果你不介意的话,我是新手。你能帮我用我的代码演示一个例子吗?我在使用你的代码后出现了这个错误。
提交给批量更新的一行或多行缺少指定的索引。
Dude!您的代码逻辑与我的代码完全不同。我使用了array_combine()函数来实现您的需求。在my foreach中,您将在$updateArray中获得适当的键和值,以便在update_批处理函数中进行更新。请参阅更重要的代码逻辑。干杯是的,我同意,但我告诉你,结果是一样的,你能不能再清楚一点你的要求?比如你想要什么样的阵列来更新?让我们来看看。