Friday, November 12, 2010

Merging two or more arrays at PHP

Share at Facebook

Its easy to merge two or more arrays at PHP. There is a simple function named array_merge() that takes two or more arrays as parameter, and return a new array after adding all of those.

$array_one = array(1, 3, 5, 7);
$array_two = array(2, 4, 6, 8);

## new array after joining
$new_array = array_merge($array_one, $array_two);

For example this tiny piece of code will join two arrays, and will produce a new array. After printing the array, you'll find the values are joined at new one.

No comments: