Solution
We can use the foreach to update the multiple invoices array.
On the constructor use the function
public function __construct(
\Magento\Sales\Api\InvoiceRepositoryInterface $invoiceRepository
){
$this->invoiceRepository = $invoiceRepository;
}
On the execute function foreach each invoice and set the value.
foreach($invoices as $invoice) {
$invoiceData2 = $this->invoiceRepository->get($invoice);
$invoiceData2->setData('variable', 'value');
$invoiceData2->save();
}
So through this, we can update multiple invoices.
Thank you.