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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Someting like this?
foreach ($subscribers as $user) {
$users[] = array(
'label' => $user->display_name,
'value' => $user->display_name
);
}
Then do the array_merge with $users
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0