I am trying to merge the results of two CodeIgniter queries. The trouble is that the two arrays contain rows of objects and array_merge()
does not work on objects. How can I merge the two object arrays.
Input:
$array1 = [
(object) [
'trainerid' => 1,
'firstname' => 'abc',
'location' => 'area',
'photo' => 'abc.jpg',
'role' => 'user',
'city' => 'bangalore',
],
(object) [
'trainerid' => 2,
'firstname' => 'abcd',
'location' => 'area',
'photo' => 'abcd.jpg',
'role' => 'user',
'city' => 'bangalore',
],
];
$array2 = [
(object) [
'rating' => 3.0000,
'users' => 0,
'review' => 0
],
(object) [
'rating' => 4.0000,
'users' => 4,
'review' => 5
]
];
Desired output:
array (
0 =>
(object) array(
'trainerid' => 1,
'firstname' => 'abc',
'location' => 'area',
'photo' => 'abc.jpg',
'role' => 'user',
'city' => 'bangalore',
'rating' => 3.0,
'users' => 0,
'review' => 0,
),
1 =>
(object) array(
'trainerid' => 2,
'firstname' => 'abcd',
'location' => 'area',
'photo' => 'abcd.jpg',
'role' => 'user',
'city' => 'bangalore',
'rating' => 4.0,
'users' => 4,
'review' => 5,
),
)