Friday, January 13, 2012

How to merge two arrays [closed]



Possible Duplicate:

How to merge these two arrays?




I've got two arrays




array(
'1' => 'string 1',
'2' => 'string 2',
'3' => 'string 3'
)

array(
'a' => 'string a',
'b' => 'string b',
'c' => 'string c'
)



What do I have to do to get this result:




array(
'1' => 'string 1',
'2' => 'string 2',
'3' => 'string 3',
'a' => 'string a',
'b' => 'string b',
'c' => 'string c'
)



Will a simple $result = array_merge($array1, $array2) suffice or just glue them together with PHP $result = $array1 . $array2

2 comments:

  1. You can use the + operator. The . operator is for strings.

    $result = $array1 + $array2;

    ReplyDelete
  2. . is for string concatenation, so yes, you would use array_merge.

    ReplyDelete