0

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 1

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

3
  • So I have this now: $data['settings']['advanced_options'] = array_merge($data['settings']['advanced_options'], [ [$users] ]); But it's throwing an error...not sure I did it right Commented Sep 2, 2020 at 17:30
  • 1
    Is just $users, not [[$users]] Commented Sep 2, 2020 at 18:01
  • That did it! Thanks so much Commented Sep 2, 2020 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.