The iPhone is still in a slump — but it may have at least hit rock bottom.

That was Wall Street’s glass-half-full take on Apple’s fiscal third-quarter results Tuesday, as the tech giant posted narrower-than-expected drops in sales and profits.

Apple sold 40.3 million iPhones in the three months ended in June — 15 percent fewer than it did in the year-ago quarter. Still, that was slightly less than the shocking, 16-percent drop iPhone unit sales saw in the March quarter, sending its shares tumbling in April.

Overall, Apple’s revenue dropped 15 percent, to $42.4 billion, with earnings down 27 percent, to $7.8 billion. Results were weighed down by sluggishness in China, where sales fell 33 percent, the company admitted.

The narrower-than-expected declines sent Apple stock 7 percent higher, to $103.41, in after-hours trades Tuesday, bringing Apple’s market capitalization to $558 billion.

The bump-up, worth $25 billion, was about double the size of the entire market value of Twitter, which also reported results late Tuesday.

In a conference call with analysts, Apple Chief Executive Tim Cook admitted that iPhone sales this year have been worse than the company originally expected.

“The iPhone upgrade rate for [the iPhone] 6s has been very similar to the 5s,” Cook said, referring to the fact that the iPhone 5 and iPhone 6 models, with their significant design improvements, boosted sales more.

“In retrospect, maybe that was a predictable thing, although we didn’t predict it at the beginning,” he said.

Looking ahead to September, Cook sounded upbeat about the release of the next iPhone, although he scrupulously avoided letting any details slip about the new gadget — including whether it will be called the iPhone 7.

Analysts have grown increasingly bearish about the upcoming iPhone after leaked pictures showed a design that’s little different from the 6s apart from a larger camera and a missing headphone jack.

“We’ll see, but I’m very optimistic about the future,” Cook said, noting the rising rates of users switching to the iPhone from other phones.

Despite initial skepticism, Apple execs said the smaller, lower-priced iPhone SE launched this spring has been a hit. That, combined with a 4-million-unit inventory reduction in higher-priced iPhones, sent average iPhone sale prices tumbling to $595 — from $662 a year earlier.

Nevertheless, that figure is poised to increase in the current quarter with the release of the new iPhone, Apple financial chief Luca Maestri said.

Elsewhere, the iPad Pro sent overall iPad revenues upward for the first time in several quarters, although overall iPad unit sales continued to drop. Mac sales also declined as designs grew stale.

Apple said that revenue from services grew 19 percent, driven by cash from App Store downloads and rising subscriptions at its stumbling Apple Music division.

For the current quarter, Apple said it expects revenues of $45.5 billion to $47.5 billion, with gross margins of 37.5 percent to 38 percent.