How to use array merge in PHP

In this article, I will explain how the array_merge() function can be used in PHP.
  • 1737

array_merge() function in PHP

  • The array_merge() function merges one or more arrays into one array.

  • In The array_merge() function, If two or more array elements have the same key, the last one overrides the others.

  • In The array_merge() function, If there is only one array, the array is numerically indexed, the keys get re-indexed in a continuous way.

Syntax

array_merge(array1,array2,array3....)

Parameter

  • array1 array1 is required parameter. determine the array name.

  • array2 array2 is optional parameter. determine the array name.

  • array3 array3 is optional parameter. specifies an array name.

Example

The following example show to how the array_merge() function can be used in PHP.

<html>

<body>

<h3 style="color: yellowgreen;">array_merge() function example in PHP</h3>

    <?php 

    $a1=array("Subject" => "<br/>Physics","<br/>Chemistry", "<br/>Biology"); 

    $a2=array("<br/>Class-XI", "<br/>Class-XII", "Section"=>"A"); 

    $result=array_merge($a1, $a2); 

    print_r($result); 

    ?> 

</body>

</html>

 

Output

merge.jpg

You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.