I’m trying to come up with a way combine two arrays that have different key names with identical values? The order of that the matching values may differ, so it would need to check if it’s a match and then merge if yes. Is there an easy way to accomplish? Any help or guidance is appreciated.
Array 1
Array
(
[0] => Array
(
[location_id] => 1
[location_title] => Centralia
[location_slug] => Centralia
[state_name] => Illinois
)
[1] => Array
(
[location_id] => 3
[location_title] => Columbia
[location_slug] => columbia
[state_name] => Illinois
)
[2] => Array
(
[location_id] => 15
[location_title] => Dixon Hennepin
[location_slug] => dixon-hennepin
[state_name] => Illinois
)
)
Array 2
Array
(
[0] => Array
(
[hours_locationid] => 3
)
[1] => Array
(
[hours_locationid] => 1
)
[2] => Array
(
[hours_locationid] => 15
)
)
Results
Array
(
[0] => Array
(
[location_id] => 1
[location_title] => Centralia
[location_slug] => Centralia
[state_name] => Illinois
[hours_locationid] => 1
)
[1] => Array
(
[location_id] => 3
[location_title] => Columbia
[location_slug] => columbia
[state_name] => Illinois
[hours_locationid] => 3
)
[2] => Array
(
[location_id] => 15
[location_title] => Dixon Hennepin
[location_slug] => dixon-hennepin
[state_name] => Illinois
[hours_locationid] => 15
)
)
Try this below,
replace $array1 and $array2 -> demo : http://codepad.org/1inDuoVe