I have multiple arrays of objects, and I'm looking for a way to merge them into a single array. Each array represents a set of ratings for different companies, and I want to combine these arrays to create a single array that contains all the ratings. Here's an example of the arrays I have:
Array 1:
Array
(
[0] => stdClass Object
(
[id] => 3
[ratingdet_id] => 2
[first_name] => Muthupandi
[company_name] => Thangam Pazhamudhir Solai - Neelampur - CBE
[ratings_name] => Store Response
[rating_val] => 3.5
[createdate] => 2023-08-31 13:18:12
)
[1] => stdClass Object
(
[id] => 4
[ratingdet_id] => 2
[first_name] => Muthupandi
[company_name] => Thangam Pazhamudhir Solai - Neelampur - CBE
[ratings_name] => Waiting Time
[rating_val] => 4
[createdate] => 2023-08-31 13:18:12
)
)
Array 2:
Array
(
[0] => stdClass Object
(
[id] => 1
[ratingdet_id] => 1
[first_name] => Muthupandi
[company_name] => Dataprime Technologies- CBE
[ratings_name] => Store Response
[rating_val] => 2.5
[createdate] => 2023-08-31 13:16:12
)
[1] => stdClass Object
(
[id] => 2
[ratingdet_id] => 1
[first_name] => Muthupandi
[company_name] => Dataprime Technologies- CBE
[ratings_name] => Waiting Time
[rating_val] => 4.5
[createdate] => 2023-08-31 13:16:12
)
)
I expect to merge these arrays into a single array that looks like this:
Merged Array:
Array
(
[0] => stdClass Object
(
[id] => 3
[ratingdet_id] => 2
[first_name] => Muthupandi
[company_name] => Thangam Pazhamudhir Solai - Neelampur - CBE
[ratings_name] => Store Response
[rating_val] => 3.5
[createdate] => 2023-08-31 13:18:12
)
[1] => stdClass Object
(
[id] => 4
[ratingdet_id] => 2
[first_name] => Muthupandi
[company_name] => Thangam Pazhamudhir Solai - Neelampur - CBE
[ratings_name] => Waiting Time
[rating_val] => 4
[createdate] => 2023-08-31 13:18:12
)
[2] => stdClass Object
(
[id] => 1
[ratingdet_id] => 1
[first_name] => Muthupandi
[company_name] => Dataprime Technologies- CBE
[ratings_name] => Store Response
[rating_val] => 2.5
[createdate] => 2023-08-31 13:16:12
)
[3] => stdClass Object
(
[id] => 2
[ratingdet_id] => 1
[first_name] => Muthupandi
[company_name] => Dataprime Technologies- CBE
[ratings_name] => Waiting Time
[rating_val] => 4.5
[createdate] => 2023-08-31 13:16:12
)
)
Can someone please guide me on how to achieve this in PHP? Should I use a loop or is there a built-in function that can help me achieve this efficiently? I want to make sure that the resulting merged array maintains the original order of objects from each source array. Any help or insights would be greatly appreciated.