我被卡住了,我找不到任何关于这个问题的提法。它不应该发生。全局变量$assignmentInfo
被传递给函数,被操作,并作为不同的变量返回。
但是,函数中的局部操作会传播到全局变量,以便下次调用函数时,$assignmentInfo
已被更改。每次调用函数时,我想传递相同的,不变的$assignmentInfo
版本。
有什么建议吗?
function studentScores($submissionInfo, $assignmentInfo){
//********************************** Add submission data to assignment data ****************************************************************************
foreach($assignmentInfo as $assignmentGroup){
foreach($assignmentGroup->assignments as $assignment){
foreach($submissionInfo as $submission){
if(isset($assignment->id) and isset($submission->assignment_id) and $assignment->id == $submission->assignment_id){
if (isset($submission->score)){$assignment->score = $submission->score;}
if (isset($submission->submitted_at)){$assignment->submitted_at = $submission->submitted_at;}
if (isset($submission->workflow_state)){$assignment->workflow_state = $submission->workflow_state;}
break;
}
}
}
}
$studentScores = $assignmentInfo;
return $studentScores;
}
$studentScores = studentScores($submissionInfo->submissions, $assignmentInfo);