Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jpeterson579's avatar

Merging 2 arrays with array_merge. Why is this not working

Why is this merge not acting the way I think it should? Code:

$newpool = array();
$newpool = array_add($newpool, 22, '1');
/// Vardump $newpool
/// array(1) { [22]=> string(1) "1" }

$array01 = Input::get('pool_ids');
/// Vardump $array01
/// array(2) { [125]=> string(1) "1" [126]=> string(1) "1" } 

$merge = array_merge($array01,$newpool);
//vardump $merge
//array(3) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(1) "1" } 

The result I am trying to get is:

array(3) { [125]=> string(1) "1" [126]=> string(1) "1" [22]=> string(1) "1" }
0 likes
2 replies
sylar's avatar
sylar
Best Answer
Level 32

$merge = $array01+$newpool;

1 like

Please or to participate in this conversation.