<?php
$array = [['Example' => 'Value']];
function hello(&$array) {
foreach ($array as &$member) {
$member['Test'] = true;
}
}
var_dump($array);
Consider the above. Why is it that ‘Test’ => true is not added to the array member [‘Example’ => ‘Value’]?
I’ve passed references down the line, so $member should be a name referring to the content [‘Example’ => ‘Value’]. I’ve even removed the & from &$member, and it is still not working. What am I misunderstanding about PHP references here?
New contributor
Shahram is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.