2
I have an object array I want to add a field in each item I do a foreach for this, but the field disappears after exiting the loop
foreach ($this->questions as $question) {
var_dump($question); // aqui é apresentado o array no estado comum
$question['survey_id'] = $survey_id;
var_dump($question); // após a adesão de um novo campo o array se modifica mostrando o campo adicionado
}
// mas aqui ele volta para seu estado natural
var_dump($this->questions);
Why does this happen?
$question
is different from$questions
. For a better understanding of the problem, specify the values present in$questions
and type of value you want to add to it.– Edilson