Array-Merge on an associative array in PHP

后端 未结 7 2139
我寻月下人不归
我寻月下人不归 2021-01-04 08:09

How can i do an array_merge on an associative array, like so:

Array 1:

$options = array (
\"1567\" => \"test\",
\"1853\" => \"test1\",
);
         


        
7条回答
  •  隐瞒了意图╮
    2021-01-04 08:43

    try using :

    $finalArray = $options + $option .see http://codepad.org/BJ0HVtac Just check the behaviour for duplicate keys, I did not test this. For unique keys, it works great.

     "test",
                      "1853" => "test1",
                      );
    
    
    $option = array (
    "none" => "N/A"
    );
    
    
    $final = array_merge($option,$options);
    
    var_dump($final);
    
    
    $finalNew = $option + $options ;
    
    var_dump($finalNew);
    
    ?>
    

提交回复
热议问题