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