0

I have two arrays as given below:

   [0] => array(5) {
    ["part_id"] => string(2) "19"
    ["maker_id"] => string(2) "29"
    ["sale_deduction_type"] => string(1) "1"
    ["sale_deduction_value"] => string(2) "10"
    ["sale_name"] => string(8) "New Year"
  }

and new one:

[0] => (6) {
        ["bill_id"] => string(2) "31"
        ["part_number"] => string(18) "SN14CNANG56-M-BLUE"
        ["part_id"] => string(2) "19"
        ["part_quantity"] => string(1) "1"
        ["part_rate"] => string(6) "232.00"
        ["part_desc"] => string(12) "this is test"
      }

how do i combine these two array1[0] and array2[0] to single array like

array[0] => (10) {
        ["bill_id"] => string(2) "31"
        ["part_number"] => string(18) "SN14CNANG56-M-BLUE"
        ["part_id"] => string(2) "19"
        ["part_quantity"] => string(1) "1"
        ["part_rate"] => string(6) "232.00"
        ["part_desc"] => string(12) "this is test"
        ["maker_id"] => string(2) "29"
        ["sale_deduction_type"] => string(1) "1"
        ["sale_deduction_value"] => string(2) "10"
        ["sale_name"] => string(8) "New Year"
  }

using array_merge or array_combine was not helpful.

user3145348
  • 105
  • 1
  • 9
  • can you post the php format of the array? That makes it easy for everybody to help. e.g. `array(array('part_id'=>19,'maker_id'=>29))` – Guns May 05 '14 at 11:52
  • 1
    If this data came from JSON, please consider passing `true` as second parameter to `json_decode()`. – Ja͢ck May 05 '14 at 11:55

2 Answers2

1

Convert object to array and try,

$obj_merged = (object) array_merge((array) $array1[0], (array) $array2[0]);

And as @jack commented above,

If this data came from JSON, please consider passing true as second parameter to json_decode()

Rikesh
  • 26,156
  • 14
  • 79
  • 87
0

You are trying to merge 2 objects of type stdClass instead of arrays. If the intended output should be an array. Convert them to arrays. Then use array_merge.

Community
  • 1
  • 1
Pinoniq
  • 1,365
  • 9
  • 13