对于数组的循环不起作用

时间:2017-01-02 07:11:50

标签: php arrays for-loop foreach

Image of array which is coming like this.

我想将所有studentId存储在一个组中

我试过这样:

我对for / foreach循环有点新意。

if($_POST['action']=='startGdstudents')  {
parse_str($_POST['participantsForGd'], $participantsForGd);
$jobID  =   $participantsForGd['jobID'];                      // example: 85
$group  =   mysqli_real_escape_string($conn,$_POST['group']); // example: 2

foreach ($participantsForGd as $k => $v){
    foreach ($v['StudentId'] as $studentid => $student){
    $q = $conn->query("INSERT INTO r_job_groups (student_id,job_id,group_id) VALUES (".$student.",".$jobID.",".$group.") ");
}
}

我的错误:

  

警告:非法字符串偏移'StudentId'    / home2 / amerytec / public_html / lc-latest / gdcontroller .php 在线    171

警告:提供的参数无效   foreach()在 / home2 / amerytec / public_html / lc-latest中   /gdcontroller.php 在线 171

警告:   为foreach()提供的参数无效    / home2 / amerytec / public_html / lc-latest /gdcontroller.php 在线    171

0 个答案:

没有答案