这就是数组的最终输出应该是这样的$dataToReset = array ( 'email_address' => $subEmail, 'status' => 'subscribed', 'interests' => array ( '1111111' => true, '2222222' => true, '3333333' => true, '4444444' => true, '5555555' => true, ));我想更换以下部分'interests' => array ( '1111111' => true, '2222222' => true, '3333333' => true, '4444444' => true, '5555555' => true,)$interestsAdd有了这样的变量$dataToReset = array ( 'email_address' => $subEmail, 'status' => 'subscribed', $interestsAdd);我得到的值和我尝试过的值如下,但没有成功!if ($form_data['lbu_multilistsvalue'] !== ''){ $groupsSelected = $form_data['lbu_multilistsvalue']; $selectedGroups = array_fill_keys(explode(",", $groupsSelected), true); $interestsAdd = ['interests' => $selectedGroups];} else { $interestsAdd = '';}
2 回答
LEATH
TA贡献1936条经验 获得超6个赞
您有多种选择,可以在数组中定义键:
$interestsAdd = [1,2,3];
$dataToReset = array (
'email_address' => 'x',
'status' => 'subscribed',
'interests' => $interestsAdd
);
或者之后添加:
$interestsAdd = [1,2,3];
$dataToReset = array (
'email_address' => 'x',
'status' => 'subscribed',
);
$dataToReset['interests'] = $interestsAdd;
或者与您当前的结构合并它们:
$interestsAdd = ['interests' => [1,2,3]];
$dataToReset = array_merge($dataToReset, $interestsAdd);
肥皂起泡泡
TA贡献1829条经验 获得超6个赞
尝试像这样设置你的第一个数组:
$dataToReset = [
'email_address' => $subEmail,
'status' => 'subscribed',
'interests' => [],
];
构建 $interestsAdd 数组后,将其添加到第一个数组:
$dataToReset['interests'] = $interestsAdd;
- 2 回答
- 0 关注
- 95 浏览
添加回答
举报
0/150
提交
取消