PHP array_merge() ফাংশন

প্রয়োগ

দুটি এক্সেক্যুটেবল ইনপুটকে একটি এক্সেক্যুটেবল ইনপুটে মিলিয়ে দিন:

<?php
$a1=array("red","green");
$a2=array("blue","yellow");
print_r(array_merge($a1,$a2));
?>

Run Instance

সংজ্ঞা ও ব্যবহার

array_merge() ফাংশন একটি বা একাধিক এক্সেক্যুটেবল ইনপুটকে একটি এক্সেক্যুটেবল ইনপুটে মিলিয়ে দেয়。

Tip:আপনি ফাংশনে একটি বা একাধিক এক্সেক্যুটেবল ইনপুট করতে পারেন。

Comment:If two or more array elements have the same key name, the last element will overwrite the other elements.

Comment:If you input only one array to the array_merge() function and the key name is an integer, then the function will return a new array with integer keys, re-indexed starting from 0 (see the example below 1).

Tip:This function is similar to array_merge_recursive() The difference between functions is in handling the case where two or more array elements have the same key name. array_merge_recursive() does not perform key name overwrite, but recursively forms an array of values with the same key name.

Syntax

array_merge(array1,array2,array3...)
Parameter Description
array1 Required. Specify an array.
array2 Optional. Specify an array.
array3 Optional. Specify an array.

Technical Details

Return Value: Return the merged array.
PHP Version: 4+
Update Log: Since PHP 5.0, this function only accepts array type parameters.

More Examples

Example 1

Merge two associative arrays into one array:

<?php
$a1=array("a"=>"red","b"=>"green");
$a2=array("c"=>"blue","b"=>"yellow");
print_r(array_merge($a1,$a2));
?>

Run Instance

Example 2

Use only one array parameter with integer keys:

<?php
$a=array(3=>"red",4=>"green");
print_r(array_merge($a));
?>

Run Instance