1:56 PM PT -- We got David leaving jail, and he tells us the gun was his and totally legal. He's got nothing but respect for the officers who arrested him, and says he'll clear everything up later today.

"Wizards of Waverly Place" starDavid Henrie -- who costarred withSelena Gomez on the show -- was just arrested for carrying a loaded gun at LAX.

Law enforcement sources tell TMZ Henrie was going through a TSA screening Monday morning at the airport and agents discovered the weapon. We're told the gun was an M&P Shield 9mm pistol and it was loaded.

Henrie was immediately detained and taken to a nearby station.

Henrie starred as Gomez's brother on "Wizards of Waverly Place" from 2007-2012. He's also made appearances on "How I Met Your Mother" and "Arrested Development." David was also on "That's So Raven" for 12 episodes withRaven-Symone andOrlando Brown.

Brown's had his fair share of run-ins with the law -- with several arrests over the years -- he was most recently caught on surveillancein a burglary.

Henrie recently revealed he and his wife, Maria Cahill, are expecting a daughter. In announcing the pregnancy, Henrie said, "That reminds me. Where's my shotgun. I don't have a shotgun. Someone get me a shotgun!"

Jake T. Austin-- who played Henrie and Gomez's younger brother on the show -- was involvedin a 4-car hit-and-run crash back in 2013.

We reached out to his reps ... so far, no word back. Henrie is still in custody.