Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $ar1 = ['a' => ['b' => 'c', 'd' => 'e']];
- $ar2 = ['a' => ['d' => 'f']];
- function merge($from, $to)
- {
- $result = $to;
- foreach ($from as $itemKey => $item) {
- foreach($item as $k => $v) {
- $result[$itemKey][$k] = $v;
- }
- }
- return $result;
- }
- echo merge($ar2, $ar1) === ['a' => ['b' => 'c', 'd' => 'f']];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement