Can't concatenate 2 arrays in PHP
Posted
by alex
on Stack Overflow
See other posts from Stack Overflow
or by alex
Published on 2010-04-16T02:22:32Z
Indexed on
2010/04/16
2:33 UTC
Read the original article
Hit count: 315
I've recently learned how to join 2 arrays using the + operator in PHP.
But consider this code...
$array = array('Item 1');
$array += array('Item 2');
var_dump($array);
Output is
array(1) { [0]=> string(6) "Item 1" }
Why does this not work? Skipping the shorthand and using $array = $array + array('Item 2')
does not work either. Does it have something to do with the keys?
© Stack Overflow or respective owner