I'm attempting to update a nested array in php. However, my updates have no effect. Here's the relevant code:
foreach($form["fields"] as $field){
Populate Checkbox Fields
if($field['type'] == 'checkbox'){
$inputs = $field['inputs'];
$count = '0';
foreach($inputs as $input){
if(($user_meta[$input['id']] !== '') && (isset($user_meta[$input['id']]))){
$select = true;
}
else{
$select = false;
}
$field['choices'][$count] = array( 'text' => $field['choices'][$count]['text'], 'value' => $field['choices'][$count]['value'] , 'isSelected' => $select );
$count = $count + '1';
}
}
}
I've tried a few different workarounds after searching for this error, but none of them seem effective. I'm grateful for any help anyone can offer.
Just use a reference &
for $field
with your existing code:
foreach($form['fields'] as &$field){
Alternately, use the key and modify the main array:
foreach($form['fields'] as $key => $field){
// later in the code
$form['fields'][$key]['choices'][$count] = array( /* ... */ );