admin管理员组文章数量:1323323
I need to get a list of users display names in a dropdown menu. I have the query right, but I'm not sure how exactly to get my user foreach inside of an array.
Here is the code I need to inject the users into:
$data['settings']['advanced_options'] = array_merge($data['settings']['advanced_options'], [
[
"label" => "Dynamic Option 1", // This is field label
"value" => "Dynamic Option 1", // This is field value
]
]);
My users are currently inside of this array:
foreach ($subscribers as $user) {
$users[] = $user->display_name;
}
How can I get the users inside of the array? The label and value need to be the same as $user->display_name
I need to get a list of users display names in a dropdown menu. I have the query right, but I'm not sure how exactly to get my user foreach inside of an array.
Here is the code I need to inject the users into:
$data['settings']['advanced_options'] = array_merge($data['settings']['advanced_options'], [
[
"label" => "Dynamic Option 1", // This is field label
"value" => "Dynamic Option 1", // This is field value
]
]);
My users are currently inside of this array:
foreach ($subscribers as $user) {
$users[] = $user->display_name;
}
How can I get the users inside of the array? The label and value need to be the same as $user->display_name
1 Answer
Reset to default 1Someting like this?
foreach ($subscribers as $user) {
$users[] = array(
'label' => $user->display_name,
'value' => $user->display_name
);
}
Then do the array_merge with $users
本文标签: phpForeach loop inside an arraymerge
版权声明:本文标题:php - Foreach loop inside an array_merge 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742141539a2422601.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论