Tutorials Point


  Learning PHP
  Advanced PHP
  PHP Function Reference
  PHP Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

PHP Function array_merge()


previous

Syntax

array array_merge ( array $array1 [, array $array2 [, array $array3...]] );

Definition and Usage

Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one.

If the input arrays have the same string keys, then the later value for that key will overwrite the previous one.

Paramters

ParameterDescription
array1Required.Specifies an array.
array2Optional.Specifies an array.
array3Optional.Specifies an array.

Return Values

It returns the resulting array.

Example

Try out following example:

<?php
$array1=array("a"=>"Horse","b"=>"Cat","c"=>"Dog");
$array2=array("d"=>"Cow","a"=>"Cat","e"=>"elephant");

print_r(array_merge($array1,$array2));
?> 

This will produce following result:

Array ( [a]=>Cat [b]=>Cat [c]=>Dog [d]=>Cow [e]=>elephant )

previous Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names