我将bson / json数据作为输出提交,如
{"waitedMS":0,"result":[{"_id":{"$id":"58131c7799fbad4c1d000205"},"fullname":"Deborah Cheryl Fox","firstmiddle":"Deborah Cheryl","firstlast":"Deborah Fox","student":{"_id":{"$id":"58131c7799fbad4c1d000205"},"student_id":5,"registration_temp_perm_no":"4","roll_no":4,"admission_date":"01\/07\/2016","first_name":"Deborah","middle_name":"Cheryl","last_name":"Fox","dob":"14\/09\/2000","gender":"Male","blood_group":"A+","birth_place":"R S","nationality":"Indian","language":"English","religion":"Agnostic","address_line1":"30933 Anderson Way","address_line2":"97 Lotheville Road","city":"R S","state":"Gujarat","pincode":"India","country":"India","phone1":"919039180422","phone2":"917681559405","email":"educianstudent@gmail.com","is_sms_enabled":"Yes","is_active":1,"has_finished":0,"student_category":"5","course":"58131c7099fbad4c1d0001c2","Biometric_ID":"4","siblings":"Cheryl Fox","guardian_name":"Cheryl Fox","guardian_occupation":"Data Coordiator","guardian_qualification":"Senior Quality Engineer","guardian_email_id":"educianparent@gmail.com","gaurdain_contact_details":"914519201577","guardian_relationship":"sapien","height":"4.4","weight":"44.8","allergies":"","batch":2,"academicyear":"2015","batchhistory":[{"batchid":2,"academic_year":"2015","course":"58131c7099fbad4c1d0001c2","sequenceno":1,"courseId":{"$id":"58131c7099fbad4c1d0001c2"}},{"batchid":3,"academic_year":"2016","course":"58131c7099fbad4c1d0001c2","sequenceno":2,"courseId":{"$id":"58131c7099fbad4c1d0001c2"}}],"uploads":{"profile_pic":"58131c7799fbad4c1d00020510.jpg"},"routearray":[{"routeid":2,"academicyear":"2016","current":1,"vehicleno":"JK01S8764","dateofassignment":"10\/30\/2016"}],"HostelAlloted":{"Food Preferences":"Both","Hostel":{"$id":"581647da99fbad9421000029"},"Floor":"Floor_1","RoomNumber":1,"Approved":"yes","Approved On":{"sec":1477852200,"usec":0},"Academic Year":"2016"},"HostelAllotmentHistory":[{"Food Preferences":"Both","Hostel":{"$id":"581647da99fbad9421000029"},"Floor":"Floor_1","RoomNumber":1,"Approved":"yes","Approved On":{"sec":1477852200,"usec":0},"Academic Year":"2016"}],"created_at":null,"updated_at":"","courseId":{"$id":"58131c7099fbad4c1d0001c2"}}}....
....
],"ok":1}
写完$cursor = $output["result"];
后
我只能获取如下所示的结果
[{"_id":{"$id":"58131c7799fbad4c1d000205"},"fullname":"Deborah Cheryl Fox","firstmiddle":"Deborah Cheryl","firstlast":"Deborah Fox","student":{"_id":{"$id":"58131c7799fbad4c1d000205"},"student_id":5,"registration_temp_perm_no":"4","roll_no":4,"admission_date":"01\/07\/2016","first_name":"Deborah","middle_name":"Cheryl","last_name":"Fox","dob":"14\/09\/2000","gender":"Male","blood_group":"A+","birth_place":"R S","nationality":"Indian","language":"English","religion":"Agnostic","address_line1":"30933 Anderson Way","address_line2":"97 Lotheville Road","city":"R S","state":"Gujarat","pincode":"India","country":"India","phone1":"919039180422","phone2":"917681559405","email":"educianstudent@gmail.com","is_sms_enabled":"Yes","is_active":1,"has_finished":0,"student_category":"5","course":"58131c7099fbad4c1d0001c2","Biometric_ID":"4","siblings":"Cheryl Fox","guardian_name":"Cheryl Fox","guardian_occupation":"Data Coordiator","guardian_qualification":"Senior Quality Engineer","guardian_email_id":"educianparent@gmail.com","gaurdain_contact_details":"914519201577","guardian_relationship":"sapien","height":"4.4","weight":"44.8","allergies":"","batch":2,"academicyear":"2015","batchhistory":[{"batchid":2,"academic_year":"2015","course":"58131c7099fbad4c1d0001c2","sequenceno":1,"courseId":{"$id":"58131c7099fbad4c1d0001c2"}},{"batchid":3,"academic_year":"2016","course":"58131c7099fbad4c1d0001c2","sequenceno":2,"courseId":{"$id":"58131c7099fbad4c1d0001c2"}}],"uploads":{"profile_pic":"58131c7799fbad4c1d00020510.jpg"},"routearray":[{"routeid":2,"academicyear":"2016","current":1,"vehicleno":"JK01S8764","dateofassignment":"10\/30\/2016"}],"HostelAlloted":{"Food Preferences":"Both","Hostel":{"$id":"581647da99fbad9421000029"},"Floor":"Floor_1","RoomNumber":1,"Approved":"yes","Approved On":{"sec":1477852200,"usec":0},"Academic Year":"2016"},"HostelAllotmentHistory":[{"Food Preferences":"Both","Hostel":{"$id":"581647da99fbad9421000029"},"Floor":"Floor_1","RoomNumber":1,"Approved":"yes","Approved On":{"sec":1477852200,"usec":0},"Academic Year":"2016"}],"created_at":null,"updated_at":"","courseId":{"$id":"58131c7099fbad4c1d0001c2"}}},
....
....
现在我想只在光标中获取学生数组。我已经写了 $ cursor = $ output ["结果"] ["学生"]。
它抛出错误"未定义索引错误消息"。
答案 0 :(得分:0)
试试这个
$cursor = $output["result"][0]['student'];
$students = array_map(function($v){return $v['student'];}, $output["result"]);