I'm trying to create an array dynamically with strings. Here is the code that I'm trying to use:
$users = get_users( $args_users );
$user_display = array();
$user_display_sorted = array();
foreach($users as $user){
echo $user->ID;
$first_name = get_user_meta($user->ID, 'first_name', true);
$last_name = get_user_meta($user->ID, 'last_name', true);
$name = $first_name.' '.$last_name;
array_push($user_display, $user->ID);
array_push($user_display, $name);
$user_display_sorted = asort($user_display);
}
print_r($user_display);
When I print the array I get the following:Array ( [0] => 5 [1] => Test Person[2] => 6 [3] => Adam Person )
I would like the output to be something like this:
Array ( [0] [ID] => 5 [name] => Test Person; [1] [ID] => 6 [name] => Adam Person)
So I'd like to do a foreach loop on the user_display_sorted array and access the variables like this:
foreach($user_display_sorted as $user_display_sort){
echo $user_display_sort->ID;
}
How can I do this?