I faced with a strange situation today. I need to change array element in foreach loop. As we know it can be done by using reference.
foreach((array)$output['subjectComposite'] as &$subjectComposite){
$subjectComposite['subjectSchemeVersion'] = $cellValue;
}
But above code doesn't work and 'subjectSchemeVersion' is not set. At the same time if I remove (array) it works:
foreach($output['subjectComposite'] as &$subjectComposite){
$subjectComposite['subjectSchemeVersion'] = $cellValue;
}
Can you explain this behaviour to me?