PHILADELPHIA — The restructuring of the Mets continued Saturday night when second baseman Neil Walker was traded to the Brewers in exchange for a player to be named.

The Mets also included cash in the trade to cover a portion of the $4.7 million remaining on Walker’s contract.

“First-rate guy, very important to the clubhouse, and I’m pretty glad we had him for the time that we did,” general manager Sandy Alderson said. “He distinguished himself as a Met.”

The player to be named won’t be announced for “some time,” Alderson said. Teams have six months to complete deals. Meanwhile, the trade eases a logjam in the Mets’ infield.

Word of the trade first trickled out as Walker finished batting practice before the Mets’ 3-1 loss to the Phillies, but the deal could not be made official until after the Brewers’ game.

Walker was scratched from the starting lineup shortly before first pitch and his bats and other belongings were removed from the dugout. During the sixth inning, Walker emerged from the clubhouse. He boarded a waiting golf cart but declined comment because the deal was not yet official.

“I really enjoyed my time here,” Walker told SNY later in the evening. “Thanks to the great fans for their support. Any trade is bittersweet. It’s always sad to go, but I’m also excited for the opportunity ahead.”

advertisement | advertise on newsday

Walker, 31, hit .264 with a .339 on-base percentage, 10 home runs and 36 RBIs in 73 games this season. He missed half of June and nearly all of July with a hamstring injury that sidelined him until three days before the July 31 non-waiver trade deadline.

The Mets fielded late interest in Walker, who nearly was moved to the Yankees at the deadline. The deal was agreed upon before the Yankees pulled the plug, citing issues with Walker’s medicals. Privately, Mets officials fumed, believing that the Yankees invoked medical concerns as a cover to back out of the trade.

Walker was upset on Friday that concerns about his medicals were made public, potentially harmful disclosures for someone who will be a free agent at season’s end. But he insisted he was healthy and the Brewers apparently agreed, reaching a deal with the Mets after a few days of negotiations.

The Mets traded Jon Niese to the Pirates for Walker before the 2015 season. Knowing that they were moving away from Daniel Murphy, the Mets regarded Walker as the best available replacement.

In 2016, Walker hit .282 and tied a career high with 23 homers. His season was cut short by surgery to correct back issues.

Mets videos

Pleased with his recovery from surgery, the Mets extended a $17.2-million qualifying offer in the offseason, and Walker accepted it. The two sides also discussed a contract extension in the offseason before revisiting those talks in spring training, but negotiations fizzled.

Walker joins a contender with the Brewers (60-59), who needed an upgrade at second base. Jonathan Villar and Eric Sogard have manned the position. Brewers second basemen have combined for a .672 OPS, last in the National League.

Before the trade, the Mets shed about $9 million in payroll, though they added $2.5 million when they acquired reliever AJ Ramos from the Marlins in a move geared toward 2018.

The Mets already had traded Addison Reed, Lucas Duda and Jay Bruce. The three deals brought back five minor-league relievers. “When things don’t go the way they were expected to go, then you have to shift direction and do the best you can,’’ Alderson said.

Curtis Granderson and Asdrubal Cabrera have cleared waivers and could be dealt before the end of the month. Said Alderson: “I still have inventory.”