以下は、という名前の多次元配列$prev_map_data
です。
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]
key からすべての値を1 つずつ取得し、その値を配列にプッシュしたいと考えています$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']);
}
}
}