以下是我的多維數組命名$prev_map_data
:在我的多維數組的foreach循環中出現什麼錯誤?
Array
(
[0] => Array
(
[class_id] => 2
[class_name] => II
[class_checked] => 1
[class_subjects] => Array
(
[0] => Array
(
[cs_map_id] => 81
[subject_name] => 11 Engllish
[subject_checked] => 1
[teacher_cs_id] => 81
)
)
)
[1] => Array
(
[class_id] => 3
[class_name] => III
[class_checked] => 1
[class_subjects] => Array
(
[0] => Array
(
[cs_map_id] => 155
[subject_name] => Hidi
[subject_checked] => 1
[teacher_cs_id] => 155
)
[1] => Array
(
[cs_map_id] => 156
[subject_name] => 11 Maths
[subject_checked] => 1
[teacher_cs_id] => 156
)
[2] => Array
(
[cs_map_id] => 157
[subject_name] => 11 Science
[subject_checked] => 1
[teacher_cs_id] => 157
)
)
)
)
我想一個擺脫關鍵[cs_map_id]
一個所有的值和數組$data
推值。但得到警告
Warning: Invalid argument supplied for foreach()
我不明白我的代碼有什麼問題。任何人都可以幫助我改進我的代碼並將值附加到新數組中嗎?提前致謝。我的代碼如下:
$prev_map_data = $objTeacherClassesSubjects->GetClassSubjectMappingsbyTeacherId ($request, $teacher_class_subjects_error_messages);
//print_d($prev_map_data);
$data = array();
foreach($prev_map_data as $map_id){
foreach($map_id as $ast){
foreach($ast as $tp){
//print_p($tp);
$tp['cs_map_id'];
array_push($data,$tp['cs_map_id']);
}
}
}
這意味着你認爲的其中一件事情是數組實際上不是數組。 – deceze 2013-05-08 09:07:07
請格式化您的代碼並添加行號 – gmaliar 2013-05-08 09:07:24
@deceze:感謝您的建議。我已經給出了我現有的多維數組供您參考。看到這個,你能糾正我的代碼嗎? – PHPLover 2013-05-08 09:09:17