I create an array which works fine:
$user_list_args = array(
'role__in' => array('editor', 'author', 'administrator' ),
);
$user_list = get_users($user_list_args);
$user_list_array = array();
foreach ( $user_list as $user ) {
$user_list_array[] = $user->user_nicename;
}
I then want to display that in an another array which is set up as follows:
array(
'id' => 'task-users',
'label' => 'User(s)',
'type' => 'select',
'options' => array(
'tom',
'jerry',
),
),
I want to change the options to be dynamic from my array as so:
private $fields = array(
array(
'id' => 'task-users',
'label' => 'User(s)',
'type' => 'select',
'options' => array($user_list_array),
),
);
This generates an error:
Fatal error: Constant expression contains invalid operations
Can someone point me in the right direction? I am using PHP7 if that helps but should be usable on older versions too.
Thanks
$user_list_arraylike that? If you want that array to contain the user's nice names, you only need to do$user_list_array[] = $user->user_nicename;$newArray[] = print_r($oldArray,true);does this do what you need?