Skip to content

Instantly share code, notes, and snippets.

@Awilum
Created March 17, 2020 08:35
Show Gist options
  • Select an option

  • Save Awilum/55b2a43c82581744a3f633fb5407ab1a to your computer and use it in GitHub Desktop.

Select an option

Save Awilum/55b2a43c82581744a3f633fb5407ab1a to your computer and use it in GitHub Desktop.
$array1 = array("PHP" => "Rasmus", "Javascript" => "Brendan", "R" => "Robert", "flextype" => ["founder" => "Sergey"], 10 => 'num1', '11' => 'num1');
$array2 = array("Java" => "James", "R" => "Ross", "Python" => "Guido", "flextype" => ['version' => '1.0'], 10 => 'num2', '11' => 'num2');
$result = array_merge($array1, $array2);
$result2 = array_replace($array1, $array2);
$result3 = array_merge_recursive($array1, $array2);
$result4 = array_replace_recursive($array1, $array2);
echo '<pre>array_merge: <br>';
print_r($result);
echo '</pre>';
echo '<pre>array_merge_recursive: <br>';
print_r($result3);
echo '</pre>';
echo '<pre>array_replace: <br>';
print_r($result2);
echo '</pre>';
echo '<pre>array_replace_recursive: <br>';
print_r($result4);
echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment