Definition và Usage

The array_merge() function merges one or more arrays into lớn one array.

Bạn đang xem: Union 2 arrays php

Tip: You can assign one array lớn the function, or as many as you like.

Note: If two or more array elements have sầu the same key, the last one overrides the others.

Note: If you assign only one array khổng lồ the array_merge() function, và the keys are integers, the function returns a new array with integer keys starting at 0 và increases by 1 for each value (See example below).

Xem thêm: phần mềm zello

Tip: The difference between this function and the array_merge_recursive() function is when two or more array elements have sầu the same key. Instead of override the keys, the array_merge_recursive() function makes the value as an array.


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

Parameter Values

Parameter Description array1 Required. Specifies an array array2 Optional. Specifies an array array3,... Optional. Specifies an array

Technical Details

Return Value: Returns the merged array PHP. Version: 4+ Changelog: As of PHP 5.0, this function only accept parameters of type array

More Examples


Merge two associative sầu arrays inkhổng lồ one array:

"red","b"=>"green"); $a2=array("c"=>"blue","b"=>"yellow"); print_r(array_merge($a1,$a2));?>
Try it Yourself »


Using only one array parameter with integer keys:

"red",4=>"green"); print_r(array_merge($a));?>
Try it Yourself »
❮ PHP Array Reference


Get certifiedby completinga course today!

obatambeienwasirherbal.com CERTIFIED . 2021
Get started

Play Game

HTML CSS JavaScript Front End Pynhỏ nhắn SQL And more

Report Error

If you want to report an error, or if you want lớn make a suggestion, do not hesitate to skết thúc us an e-mail:



Thank You For Helping Us!

Your message has been sent khổng lồ obatambeienwasirherbal.com.

Top Tutorials HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial Squốc lộ Tutorial Pykhiêm tốn Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
Top References HTML Reference CSS Reference JavaScript Reference Squốc lộ Reference Pythuôn Reference W3.CSS Reference Bootstrap Reference PHPhường. Reference HTML Colors Java Reference Angular Reference jQuery Reference
Top Examples HTML Examples CSS Examples JavaScript Examples How To Examples SQL Examples Pybé Examples W3.CSS Examples Bootstrap Examples PHPhường. Examples Java Examples XML Examples jQuery Examples
Web Courses HTML Course CSS Course JavaScript Course Front End Course Squốc lộ Course Pydong dỏng Course PHP Course jQuery Course Java Course C++ Course C# Course XML Course Get Certified »
obatambeienwasirherbal.com is optimized for learning và training. Examples might be simplified lớn improve reading và learning. Tutorials, references, và examples are constantly reviewed to lớn avoid errors, but we cannot warrant full correctness of all content. While using obatambeienwasirherbal.com, you agree khổng lồ have sầu read & accepted our terms of use, cookie & privacy policy. Copyright 1999-2021 by Refsnes Data. All Rights Reserved. obatambeienwasirherbal.com is Powered by W3.CSS.