Here's my code:
$get_access_keys_from_wp = get_user_meta( $user_id, '_tdv_volunteer_positions' );
$new_access_keys = array();
if ( $get_access_keys_from_wp ) {
echo "This user is signed up for other positions.";
$current_access_keys = $get_access_keys_from_wp;
foreach($current_access_keys as $key => $value) {
$new_access_keys[] = $value;
}
//$new_access_keys[] = $position_post_id;
$new_access_keys[] = array('position_id' => $position_post_id, 'volunteer_first_name' => $first_name, 'volunteer_last_name' => $last_name);
} else {
echo "This user is not signed up for any positions.";
//$new_access_keys[] = $position_post_id;
$new_access_keys[] = array('position_id' => $position_post_id, 'volunteer_first_name' => $first_name, 'volunteer_last_name' => $last_name);
}
Initially, I get the following:
Array
(
[0] => Array
(
[0] => Array
(
[position_id] => 67
[volunteer_first_name] => Mike
[volunteer_last_name] => Jackson
)
)
)
And that's great ... I want it like this. But as you can see by the logic above, I need to be able to loop over the array if it already exists, and add to it so that it looks like the following:
Array
(
[0] => Array
(
[0] => Array
(
[position_id] => 67
[volunteer_first_name] => Mike
[volunteer_last_name] => Jackson
)
[1] => Array
(
[position_id] => 68
[volunteer_first_name] => Mike
[volunteer_last_name] => Jackson
)
)
)
But instead, I'm getting results like this:
Array
(
[0] => Array
(
[0] => Array
(
[0] => Array
(
[position_id] => 67
[volunteer_first_name] => Mike
[volunteer_last_name] => Jackson
)
)
[1] => Array
(
[position_id] => 68
[volunteer_first_name] => Mike
[volunteer_last_name] => Jackson
)
)
)
$get_access_keys_from_wpin$current_access_keysis necessary, since you don't seem to modify either afterwards.