Irvine-based Western Digital Corp. plans to buy Milpitas-based SanDisk Corp. for $19 billion in cash and stock.

Western Digital would raise most of the money for the acquisition by taking on new debt with the ratio of cash-to-stock affected based on whether the previously announced $3.8 billion investment in Western Digital by China-based Unisplendour Corp. Ltd. has closed by the time the SanDisk deal does.

The headquarters of the company will remain in Irvine, the announcement said.

The two companies were each up about 4% in early morning trading but have settled a bit since.

Western Digital is up about 2% to $76.50 and a $17.7 billion market cap.

SanDisk is up about 3% to $77.40 and a $15.8 billion market cap.

The deal values SanDisk at $86.50 a share.