<?php $arr1 = [ [ "id"=>"3", "weight"=>"20", "percentage"=>"80", ], [ "id"=>"1", "weight"=>"50", "percentage"=>"80", ], [ "id"=>"2", "weight"=>"40", "percentage"=>"80", ] ]; $arr2 = [ [ "id"=>"1", "stock"=>"9539.00" ], [ "id"=>"2", "stock"=>"9468.00" ], [ "id"=>"3", "stock"=>"9295.00" ] ]; $keys = array_flip(array_column($arr2, 'id')); $newArr = array_map(function($item) use($keys, $arr2){ $item['stock'] = $arr2[$keys[$item['id']]]['stock']; return $item; }, $arr1); var_dump($newArr);
You have javascript disabled. You will not be able to edit any code.