Combine two arrays on key/value and output combined array with PHP

后端 未结 2 929
刺人心
刺人心 2021-01-25 21:26

Racking my brain on this, found many examples of similar situations however the solutions don\'t seem to match up.

I have two arrays being built as the result of SQL que

2条回答
  •  自闭症患者
    2021-01-25 22:01

    Assuming your first array as $first and second array as $second

    foreach ($first as $key => $each) {
      foreach ($second as $secondeach) {
        if($secondeach['sku'] == $key) {
          $first[$key] = array_merge($first[$key], $secondeach);
          // unset since you do not want LocalSKU value anymore.
          unset($first[$key]['LocalSKU']);
        }
      }
    }
    

    $first is your array you wanted.

提交回复
热议问题