dongwang6837 2016-04-23 13:39
浏览 131

在php中使用多维数组的array_merge

using this foreach loop :

foreach($course_presence as $key => $value){
    $presence_arr[$value['student']] = array();
    array_push($presence_arr[$value['student']],$value); 
}

i create array that its keys are the students id's . student id = $value['student'].(1,2,3...)

$value has the following structure exp: array(3) { ["student"]=> string(1) "1" ["course"]=> string(4) "1111" ["date"]=> string(19) "2016-03-17 10:25:00" }

why if this loop executes 10 times for two different ids i dont get all the arrays for each student id?

EXAMPLE: in my case currently the loop iterates over this data:

array(3) { ["student"]=> string(1) "1" ["course"]=> string(4) "1111" ["date"]=> string(19) "2016-03-17 10:25:00" }
 array(3) { ["student"]=> string(1) "5" ["course"]=> string(4) "1111" ["date"]=> string(19) "2016-01-01 10:00:00" }
 array(3) { ["student"]=> string(1) "5" ["course"]=> string(4) "1111" ["date"]=> string(19) "2016-01-22 00:00:00" } 
array(3) { ["student"]=> string(1) "5" ["course"]=> string(4) "1111" ["date"]=> string(19) "2016-02-14 00:00:00" }
 array(3) { ["student"]=> string(1) "5" ["course"]=> string(4) "1111" ["date"]=> string(19) "2016-02-28 00:00:00" }
 array(3) { ["student"]=> string(1) "1" ["course"]=> string(4) "1111" ["date"]=> string(19) "2016-02-14 14:00:00" }
 array(3) { ["student"]=> string(1) "5" ["course"]=> string(4) "1111" ["date"]=> string(19) "2016-03-27 00:00:00" }

and var_dump of the presence_arr is this:

    array(2) { 
[1]=> array(1) { [0]=> array(3) { ["student"]=> string(1) "1" ["course"]=> string(4) "1111" ["date"]=> string(19) "2016-02-14 14:00:00" } }
 [5]=> array(1) { [0]=> array(3) { ["student"]=> string(1) "5" ["course"]=> string(4) "1111" ["date"]=> string(19) "2016-01-03 05:00:00" } } }

as you cans the merge ran over and replaced the value in each index instead of merging? ani idea what causing that? thx

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥40 复杂的限制性的商函数处理
    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码