$array = array() {
[0]=> array(6) {
["id"]=> string(1) "2"
["lessonid"]=> string(3) "200"
["userid"]=> string(4) "6038"
["username"]=> string(8) "jsc11101"
["lessontitle"]=> string(47) "Module1-Unit2 I'm From China "
["courseid"]=> string(1) "4"
}
[1]=> array(6) {
["id"]=> string(1) "3"
["lessonid"]=> string(3) "201"
["userid"]=> string(4) "6038"
["username"]=> string(8) "jsc11101"
["lessontitle"]=> string(33) "Module2-Unit1 I Can Speak English"
["courseid"]=> string(1) "4"
}
[5]=> array(6)
。。。。。。。。。。。。。。。。。。。。。。。。
}
相同lessonid的學習次數
$study_num = array();
foreach($array as $value){
$study_num[$value['lessonid']]=(empty($study_num[$value['lessonid']])?0:$study_num1[$value['lessonid']])+1;
//如果$study_num[$value['lessonid']為第一次遍 歷賦值為空
}
學習次數: $study_num[$lessionid]
轉換成以lessonid為key的數組
$lessonid_array = array();
foreach($array as $key => $value){
$lessonid_array[$value[lessonid]]=$value;
}
學習課文名稱: $lessonid_array[$lessonid]['lessontitle']
合並數組
foreach($study_num as $key=>$value){
$lessonid_array[$key][count]=$value;
}
輸出數組形式如下
$a_array = array(){
lessonid號 => array(7) {
["id"]=> string(1) "3"
["lessonid"]=> string(3) "學習課文ID"
["userid"]=> string(4) "6038"
["username"]=> string(8) "jsc11101"
["lessontitle"]=> string(33) "學習課文名稱"
["courseid"]=> string(1) "4"
["count"]=>"學習次數"
}
}