How to break nest loop (problems)

Run Settings
LanguagePHP
Language Version
Run Command
<?php $investList = [ [ 'id' => 1, 'cash' => 1000, ], [ 'id' => 2, 'cash' => 4000, ], [ 'id' => 3, 'cash' => 1000, ], [ 'id' => 4, 'cash' => 3000, ], [ 'id' => 5, 'cash' => 2000, ], ]; $refundList = [ [ 'invest_id' => 1, 'cash' => 1000, ], [ 'invest_id' => 2, 'cash' => 4000, ], [ 'invest_id' => 3, 'cash' => 1000, ], [ 'invest_id' => 4, 'cash' => 3000, ], [ 'invest_id' => 5, 'cash' => 2000, ], ]; foreach($refundList as $index => $refund) { foreach($investList as $invest) { if($invest['id'] == $refund['invest_id']) { $refundList[$index]['invest_cash'] = $invest['cash']; } } } print_r($refundList); //When the investList run up to 10000, the loop times can be 10000*10000=100000000, how to optimize this? //Solution: https://glot.io/snippets/eggpzzp1tm
Editor Settings
Theme
Key bindings
Full width
Lines