Parkour\Transform::merge PHP Method

merge() public static method

Merges two arrays recursively.
public static merge ( array $first, array $second ) : array
$first array Original data.
$second array Data to be merged.
return array Merged data.
    public static function merge(array $first, array $second)
    {
        foreach ($second as $key => $value) {
            $shouldBeMerged = isset($first[$key]) && is_array($first[$key]) && is_array($value);
            $first[$key] = $shouldBeMerged ? self::merge($first[$key], $value) : $value;
        }
        return $first;
    }

Usage Example

 /**
  *
  */
 public function testMerge()
 {
     $first = ['one' => 1, 'two' => 2, 'three' => ['four' => 4, 'five' => 5]];
     $second = ['two' => 'two', 'three' => ['four' => 'four']];
     $expected = ['one' => 1, 'two' => 'two', 'three' => ['four' => 'four', 'five' => 5]];
     $this->assertEquals($expected, Transform::merge($first, $second));
 }
All Usage Examples Of Parkour\Transform::merge