array
(
[0] => array
(
[statusa] => 1
[laiyuan] => 287
[stotala] => 148
)
)
array
(
[0] => array
(
[status] => 1
[laiyuan] => 287
[stotal] => 148
)
)
上面两个数组如何根据laiyuan合并成如下新的数组:
array
(
[0] => array
(
[status] => 1
[statusa] => 1
[laiyuan] => 287
[stotal] => 148
[stotala] => 148
)
)
谢谢大家,感激不尽。
回复讨论(解决方案)
$a = array(
array(
‘statusa’ => 1,
‘laiyuan’ => 287,
‘stotala’ => 148,
)
);
$b = array(
array(
‘status’ => 1,
‘laiyuan’ => 287,
‘stotal’ => 148,
)
);
$c = array_map(‘array_merge’, $a, $b);
print_r($c);
array
(
[0] => array
(
[statusa] => 1
[laiyuan] => 287
[stotala] => 148
[status] => 1
[stotal] => 148
)
)
感谢版主大人@xuzuning 有个小问题想再次问问哈,我把查询出来的两个数组和结果一起贴出来哈!
数组a
array
(
[0] => array
(
[status] => 0
[laiyuan] => 287
[stotal] => 26
)
[1] => array
(
[status] => 0
[laiyuan] => 288
[stotal] => 2
)
[2] => array
(
[status] => 0
[laiyuan] => 289
[stotal] => 17
)
[3] => array
(
[status] => 0
[laiyuan] => 290
[stotal] => 1
)
[4] => array
(
[status] => 0
[laiyuan] => 356
[stotal] => 2
)
[5] => array
(
[status] => 0
[laiyuan] => 370
[stotal] => 6
)
)
数组b
array
(
[0] => array
(
[statusa] => 1
[laiyuan] => 287
[stotala] => 148
)
[1] => array
(
[statusa] => 1
[laiyuan] => 288
[stotala] => 7
)
[2] => array
(
[statusa] => 1
[laiyuan] => 289
[stotala] => 168
)
[3] => array
(
[statusa] => 1
[laiyuan] => 290
[stotala] => 1
)
[4] => array
(
[statusa] => 1
[laiyuan] => 294
[stotala] => 8
)
[5] => array
(
[statusa] => 1
[laiyuan] => 356
[stotala] => 11
)
[6] => array
(
[statusa] => 1
[laiyuan] => 370
[stotala] => 21
)
[7] => array
(
[statusa] => 1
[laiyuan] => 383
[stotala] => 1
)
)
运行结果
array
(
[0] => array
(
[status] => 0
[laiyuan] => 287
[stotal] => 26
[statusa] => 1
[stotala] => 148
)
[1] => array
(
[status] => 0
[laiyuan] => 288
[stotal] => 2
[statusa] => 1
[stotala] => 7
)
[2] => array
(
[status] => 0
[laiyuan] => 289
[stotal] => 17
[statusa] => 1
[stotala] => 168
)
[3] => array
(
[status] => 0
[laiyuan] => 290
[stotal] => 1
[statusa] => 1
[stotala] => 1
)
[4] => array
(
[status] => 0
[laiyuan] => 294
[stotal] => 2
[statusa] => 1
[stotala] => 8
)
[5] => array
(
[status] => 0
[laiyuan] => 356
[stotal] => 6
[statusa] => 1
[stotala] => 11
)
[6] =>
[7] =>
)
有几条数据不见了呢!比如这条
[6] => array
(
[statusa] => 1
[laiyuan] => 370
[stotala] => 21
)
array_merge 要求规模一样
那版主大人这类的数组有什么办法可以操作出来吗??我只是想实现
laiyuan stotala stotal
这样一个表格而已。。。。
两表关联查询
array
(
[0] => array
(
[status] => 0
[laiyuan] => 287
[stotal] => 26
)
[1] => array
(
[status] => 0
[laiyuan] => 288
[stotal] => 2
)
[2] => array
(
[status] => 0
[laiyuan] => 289
[stotal] => 17
)
[3] => array
(
[status] => 0
[laiyuan] => 290
[stotal] => 1
)
[4] => array
(
[status] => 0
[laiyuan] => 356
[stotal] => 2
)
[5] => array
(
[status] => 0
[laiyuan] => 370
[stotal] => 6
)
[6] => array
(
)
[7] => array
(
)
)
改這樣再用上面的方法.
例如: