Merging associative and non associative arrays with array_merge()

array_merge() is a php function that merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array.

Example code:

<?php
$beginning = 'foo';
$end = array(1 => 'bar');
$result = array_merge((array)$beginning, (array)$end);
print_r($result);
?>

The output is
Array
(
[0] => foo
[1] => bar
)

Share Article/Example:
  • DotNetKicks
  • DZone
  • StumbleUpon
  • Print
  • Add to favorites
  • Digg
  • del.icio.us
  • Twitter
  • Facebook
  • LinkedIn
  • Posterous
  • Slashdot

 

 
eXTReMe Tracker