0

I'm trying to store a list of user emails in array to be used in an API call. Here is my current code:

function getPlayerEmailsByFolderId($userId){
  $args = array(
    'role'        => 'subscriber',
    'meta_key'      => 'player_team_id',
    'meta_value'    => $userId
  );
  $players = new WP_User_Query( $args );
  $contactList = array();
  if ( ! empty( $players->results ) ) {
    foreach ($players->results as $player) {
      $player_email = $player->user_email;
      $contactList[] = array(
          'email'=> $player_email;
      );
    }
  }
  return $contactList;
}

//Get all players on a team via the coach's ID
$emails = getPlayerEmailsByFolderId($userId);

The $contactList[] = array(......); inside the foreach loop is what's causing my code to break, but I can't figure out why. Is my syntax bad?

mickdeez
  • 507
  • 3
  • 7
  • 16

1 Answers1

1

'email'=> $player_email; Remove the semicolon at the end of the line ... your IDE should warn you about this. If you're not using one I can recommend you to start using it. You can use VSCode or PHPStorm for instance

Bezdutchek
  • 77
  • 1
  • 8
  • Thanks so much. Will check out PHPStorm. Just coding in Atom for now and uploading to site.. Still new to all of this! – mickdeez Mar 09 '21 at 17:52