Friday, November 12, 2010

Merging two or more arrays at PHP

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);
print_r($new_array);



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:

Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...