Walmart reported better-than-expected second-quarter earnings and raised its yearly forecast as inflation-battered shoppers flocked to its low-priced food, clothing and home goods.

Walmart shone thanks to its affordability. Comparable sales, excluding fuel, rose 4.2% in the second quarter since the same period last year, beating expectations.

Its online sales soared 22% in the US and customers spent more than usual, with transactions up 3.6% and average spending rising 0.6% since the same period last year.

Walmarts big box chain Sams Club sales grew 5.2%, which fell in line with expectations.

“Everyone feels relief that everything is ok with the consumer because of Walmart’s results, but a lot of higher income people are trading down to Walmart, so people are trying to save where they can,” Edward Jones analyst Brian Yarbrough told The Post.

The Arkansas-based retail giant’s shares spiked 6.7% on the strong earnings report Thursday, peaking at $74.07 a share. 

Prior to the jump, the companys stock was up about 30% so far this year above the S&P 500s 15% growth.

Walmart reported adjusted earnings per share of 67 cents, topping LSEG analysts expectations of 65 cents.

The retailer raked in revenue of $169.34 billion, above analysts estimates of $168.63 billion and up nearly 5% since the same period last year.

The Arkansas-based company raised its sales expectations between 3.75% and 4.75% from 3% and 4%. 

It hiked its earnings per share predictions between $2.35 and $2.43 a share from $2.23 and $2.37 a share.

The only place anyone is shopping right now is Amazon, Walmart and Costco, Michael Baker, an analyst at DA Davidson, told CNN. 

The retailer took steps to cater to cash-strapped customers. It ramped up its advertising efforts and launched a value grocery brand called Bettergoods selling meals like chicken wings and frozen pizzas for less than $5.

Walmart also has been reaping the benefits as consumers search for cheaper alternatives to fast food an industry which has struggled to draw back customers stung by sticker shock.

McDonalds, Burger King and other fast food giants have gone head-to-head releasing value meals in an effort to boost dismal sales.

It stands to reason that customers are shifting to prepare more meals at home versus eating out, Walmart CFO John David Rainey told CNBC.

Walmart’s prices fall about 25% lower than traditional supermarkets, according to analysts.

About 60% of Walmart’s sales come from groceries and the retail giant has been grabbing market share from traditional supermarkets, including Kroger and Albertsons, according to CFRA analyst Arun Sundaram.

Sales of general merchandise, like lawn and garden supplies, also increased slightly growing for the first time in 11 quarters, which Rainey called an encouraging sign.

The CFO said Walmart has noticed a positive shift in consumer sentiment over the past year.

Rainey said every month of the quarter was relatively consistent and the back-to-school season is off to a pretty good start despite data predicting one of the most expensive back-to-school shopping seasons yet.

We see, among our members and customers, that they remain choiceful, discerning, value-seeking, focusing on things like essentials rather than discretionary items, but importantly, we dont see any additional fraying of consumer health, Rainey said.

Walmarts earnings grew on increased sales, not price hikes, he said.

Customers have turned to Walmart after being stretched thin by price hikes at other grocery stores, restaurants and retailers.

A weak July jobs report which revealed high unemployment growth added to the pain, causing chaos and a massive market sell-off.

Inflation has been cooling, though. US inflation rose 2.9% last month versus a year ago slightly below expectations. 

And retail sales jumped 1.0% in July the largest increase since January 2023, after a 0.2% drop in June.

But even though the US is not currently in a recession, three in five people believe it is, according to new research. 

Net income dropped to $4.5 billion, or 56 cents per share down from $7.89 billion, or 97 cents per share, in the same period last year.

While Walmart has soared, competitors like Home Depot have slashed their sales forecasts.

The home improvement chain blamed its poor second-quarter earnings on high interest rates and fears of a market crash.

Richard McPhail, Home Depots chief financial officer, told CNBC on Tuesday that consumers have adopted a deferral mindset since the middle of last year so theyre spending less on home improvement projects. 

Theyre deferring because of a sense of greater uncertainty in the economy,” he said.

Retail analyst Hitha Herzog said Walmart has been able to appeal to consumers by offering particularly low prices on everyday goods.

“Why would you go to Home Depot for paper towels when you can get them delivered to your home at a 25% cheaper price and potentially free delivery — which is what Walmart offers,” Herzog, chief research officer at H Squared Research and part time faculty at Parsons School of Design, told The Post in a statement.

Home Depot shares are up 4.4% compared to Walmarts 37.6% growth so far this year.

Walmart’s gain in such categories as household goods and apparel and appliances has come at others’ expense, namely Target, which has had soft sales for the past several quarters, Yarbrough told The Post.

Target shares have fallen 1.30% so far this year.

While Walmart raised its full-year guidance, it warned its second-half results may miss Wall Street expectations. 

Walmart expects adjusted earnings between 51 to 52 cents per share in the third quarter, below analysts expectations of 54 cents. And analysts’ earnings predictions fall at the top of Walmart’s guidance.

Rainey said the retailer didnt raise its second-half guidance since a number of factors may significantly sway the market this year including the 2024 US elections and tensions in the Middle East. 

In this environment, its responsible or prudent to be a little bit guarded with the outlook, but were not projecting a recession, he told CNBC.